这是 HTML (此表单可能使用两次以上) :-(
<div class="abc">
<div class="xyz">
<input type="text" name="pqr" />
<div class="clickMe">click button</div>
<div class="showContent"></div>
</div>
<div class="somethingelse">some other insignificent input or something else.</div>
</div>
这是jQuery:
$('.clickMe').on('click', function(e){
$.post("getdata.php", $(this).closest('.abc').children('.xyz').children('input[name="pqr"]').serialize(), function(response) {
$(this).closest('.abc').children('.xyz').children('.showContent').html(response);
});
});
我只需要用我的数据库检查输入(PQR)的数据?
任何想法,我怎么能做到,我的代码出了什么问题!
提前感谢。
帖子内部的this
范围与帖子外部不同
$('.clickMe').on('click', function(e){
e.preventDefault();
var xyz = $(this).closest('.abc').children('.xyz');
$.post("getdata.php", xyz.children('input[name="pqr"]').serialize(), function(response) {
xyz.children('.showContent').html(response);
});
});