如何在php中使用jquery在对话框中获取文本框的值,我将其作为空白或未定义
How to get value of a text box in a dialog box using jquery in php, i get it as blank or undefined
如何在php中使用jquery获取对话框中文本框的值。我正在打开一个对话框,点击按钮,其中有一个文本框作为评论。我想把这个值提交给数据库。但是当我警告它时,我得到的值是未定义的或空白的。我无法获取文本框的消息值。我的代码如下:
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$(".QTPopup").css('display','none');
$(".lnchPopop").click(function(){
$(".QTPopup").animate({width: 'show'}, 'slow');});
$(".closeBtn").click(function(){
$(".QTPopup").css('display', 'none');
});
$(document).on('click','.submit_comment',function(){
alert("Hello");
var comments=$('#comment_by_user').val();
alert(comments);
var comments1= document.getElementById("comment_by_user").value;
alert(comments1);
});
});
</script>
单击注释超链接,对话框将打开。
a href="#" class="lnchPopop">Comments</a>
<div class="QTPopup" style="display: none">
<div class="QTPopupCntnr">
<div class="gpBdrLeftTop"></div>
<div class="gpBdrRightTop"></div>
<div class="gpBdrTop"></div>
<div class="gpBdrLeft">
<div class="gpBdrRight">
<div class="caption">
Send Your Messages
</div>
<a href="#" class="closeBtn" title="Close"></a>
<div class="content">
<br />
<table>
<tr>
<td style="height:5px;"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<textarea class="textareagradiant" id="comment_by_user" name="comment_by_user"
style="width:428px; height:116px; border:1px solid #CFCECE;"> </textarea>
</td>
</tr>
<tr>
<td style="height:5px;"></td>
</tr>
<tr>
<td style="height:10px;"></td>
</tr>
<tr>
<td>
<input type="button" value="Submit" class="gbtn_s submit_comment" />
<input type="button" value="Reset" class="gbtn_s" />
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="gpBdrLeftBottom"></div>
<div class="gpBdrRightBottom"></div>
<div class="gpBdrBottom"></div
</div>
</div>
删除警告("Hello");
$(document).ready(function(){
$(".QTPopup").css('display','none');
$(".lnchPopop").click(function(){
$(".QTPopup").animate({width: 'show'}, 'slow');});
$(".closeBtn").click(function(){
$(".QTPopup").css('display', 'none');
});
$(document).on('click','.submit_comment',function(){
var comments=$('#comment_by_user').val();
alert(comments);
var comments1= document.getElementById("comment_by_user").value;
alert(comments1);
});
});
您的代码似乎工作良好。确保你修改了第一行
<a href="#" class="lnchPopop">Comments</a>
工作副本可以在这里找到:http://jsfiddle.net/6LXSn/1/.
我通常使用jQuery AJAX调用来获取php的值。$.ajax({
type: "POST",
url: 'your php script',
data: {
comments: comments
},
dataType: 'html',
async: false,
error: function(obj, text, error) {
},
success: function(response) {
}
});
然后在PHP中检索你的注释值
$_POST['comments']
希望能有所帮助
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 有了字段的名称,我如何用空白数据初始化对象的未定义字段
- 为什么我的 JavaScript 提升的局部变量返回未定义,但提升的全局变量返回空白
- 谷歌地图 - 当地图应该显示时,有时会发生“未定义”错误或地图为空白.如何预防
- 我得到一个空白值和未定义的索引
- 如何在php中使用jquery在对话框中获取文本框的值,我将其作为空白或未定义
- 检查AJAX响应数据是否为空/空白/null/未定义/0
- 如何在Javascript中传递空白值而不是未定义