我有这个代码
<input type='submit' name='sub_form' value='Save'>
和<a href="#" class="close">Cancel</a>
和jQuery是
$('td.add_text').click(function(e) {
$('<img src="images/ajaxLoader.gif" id="loading" style="width:auto;" />').appendTo(".quotation_computation");
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var ccom = $( 'input[name=com_code]' ).val();
var ucom = $( 'input[name=user_code]' ).val();
var in_form = $( 'input[name=in_form]' ).val();
var ctrack = $( 'input[name=com_for_track]' ).val();
$.ajax({
type:"GET",
url:"forms/tem.php",
data: {uc: ucom, cc: ccom, ct: ctrack, in_f: in_form },
dataType: 'html',
target: '.quotation_computation',
success: function(data){
$(".quotation_computation").find('img#loading').remove();
$(".quotation_computation").html(data);
}
})
});
和关闭按钮jquery
$(".close").click(function () {
$(".quotation_computation").hide();
});
和html
<div class="quotation_computation">
ANOTHER JQUERY PROBLEM
</div>
当我点击关闭按钮时,它不起作用。
我的关键按钮错了吗?
好的,当我点击div class="quotation_computation">
jquery ajax工作正常并保存到我的数据库。但当我点击Cancel
按钮时,jquery ajax或表格仍在那里。
有什么我需要改变的吗?
答案 0 :(得分:1)
单击<a href="#">
锚标记将具有默认操作,即它将强制页面刷新。您必须阻止此默认操作,否则它将刷新页面并重新打开您刚刚隐藏的元素。
$('.close').click(function(e) {
$('.quotation_computation').hide();
e.preventDefault();
});