我正在使用 preventDefault 函数来阻止我的表单提交。这工作正常,但是在该功能之后,我有一个不再工作的 onClick 功能。
奇怪的是,在 onclick 功能之前,我确实有一个简单的 div 居中功能,即使遵循 preventDefault 形式也能正常工作。
编辑:我发现了问题,onclick 函数是针对在第一个函数中通过 ajax 加载的项目。所以选择器可能没有找到它
下面是我的代码:
// Submit zip code
$("#get_zip").submit(function (zip)
{
//Send zipcode
$.ajax({
type: "POST",
url: "ajax_calls.php",
data: "zip="+$('#zip').val()+"&send_zip=true",
success: function(listing){$("#wrapper").html(listing); $("#lightbox,#welcome").fadeOut(300);},
error: function(){alert(3);$("#error").text("Could not retrieve posts").fadeIn(300).delay(900).fadeOut(300)}
});
//Stop form submission action
zip.preventDefault();
});
//Center item box
$("#item").centerInClient();
//When clicking an item row
$("tr.item").click(function()
{
// Get item id from selected row id
var id = $(this).attr('id');
//Fill item box with item details
$.ajax({
type: "POST",
url: "ajax_calls.php",
data: "id="+id+"&get_item=true",
success: function(r){$("#item_detail").html(r); $("#lightbox, #item").fadeIn(300);},
error: function(){alert(2);$("#error").text("Could not retrieve posts").fadeIn(300).delay(900).fadeOut(300)}
});
});
对此的任何帮助将不胜感激。
非常感谢