显示内的jQuery val():无 [英] jQuery val() inside display: none
本文介绍了显示内的jQuery val():无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<a href="#addFriend" rel="facebox" title="[+] add <?php echo $showU["full_name"]; ?> as friend">
<div class="addFriend"></div></A>
<div id="addFriend" style="display:none; margin: auto;">
<form action="javascript:DoFriendRequest()" method="post">
<input name="commentFriend" type="text" id="commentFriend" value="" size="22">
<input name="submit" type="submit" id="submit" value="Send">
</form>
</div>
当我的表单位于该元素(即jquery灯箱)中时,字段#commentFriend
在DoFriendRequest中获取空值
My form when it's inside this element which is a jquery lightbox, the field #commentFriend
get empty value in DoFriendRequest
function DoFriendRequest() {
var wrapperId = '#insert_svar';
$.ajax({
type: "POST",
url: "misc/AddFriendRequest.php",
data: {
mode: 'ajax',
comment : $('#commentFriend').val()
},
success: function(msg) {
$(wrapperId).prepend(msg);
$('#commentFriend').val("");
}
});
}
更新后的答案
但是当我删除display:none
时,它可以工作.我该如何解决?
But when I remove the display:none
, it works. How can I solve this?
推荐答案
对于具有display:none
的字段,看来val()
不起作用.
For fields with display:none
, it seems that val()
does not work.
我通过attr()
绕过此行为:
$('input').attr('value',myNewValue);
这篇关于显示内的jQuery val():无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文