我在悬停时加载一个 jQuery qtip(因为它通常有效)。在这个 qtip 里面,有一个文本框和一个按钮。点击这个按钮,我想用这个文本框的值做一些事情。不知何故,jQuery 的 .val() 函数返回了文本框的初始值。我哪里错了?
jQuery代码:
$(function() {
$("#someplace").qtip({
content: $("#popup"),
hide: {
fixed: true
},
position: {
corner: {
tooltip: 'topMiddle',
target: 'bottomMiddle'
},
adjust: {
x:-30,
y:-75
}
},
style: {
width:'100px',
color:'white',
name:'tspopup'
}
});
$("#button_in_the_qtip").click(
function () {
var txt = $("#textbox_in_the_qtip").val();
alert($("#textbox_in_the_qtip").attr('id')); // This returns "textbox_in_the_qtip"
alert(txt); // This returns "abc" <---- Problem
}
);
});
弹出 qtip 的 HTML 代码:
<div style="display:none;" id="popup">
<table cellpadding="5px" border="1" style="margin-top:12px; margin-bottom:12px; color:#fff; font-size:.7em;">
<tr>
<td>
<input type="text" id="textbox_in_the_qtip" value="abc" />
</td>
<td>
<button id="button_in_the_qtip">Add</button>
</td>
</tr>
</table>
</div>