Javascript e、 防止qtip中的默认提交问题
我正试图让我的表单在qtip工具提示中提交而不加载页面。但是,我似乎无法让它在单击提交后停止加载页面。它可以在href上正常工作,但不能在表单中的提交按钮上正常工作Javascript e、 防止qtip中的默认提交问题,javascript,php,jquery,forms,Javascript,Php,Jquery,Forms,我正试图让我的表单在qtip工具提示中提交而不加载页面。但是,我似乎无法让它在单击提交后停止加载页面。它可以在href上正常工作,但不能在表单中的提交按钮上正常工作 //This One Is BROKEN $('#EditGallerySubmit').on('submit', function (e) { e.preventDefault(); }); //This One Is Working Good As Expected $('.EditGallery').on('cli
//This One Is BROKEN
$('#EditGallerySubmit').on('submit', function (e) {
e.preventDefault();
});
//This One Is Working Good As Expected
$('.EditGallery').on('click', function (e) {
e.preventDefault();
});
$('.EditGallery').each(function()
{
$(this).qtip({
content: {
text: "Loading...",
ajax: {
url:$(this).attr('href'),
type: "GET",
success: function(data, status) {
this.set('content.text', data);
$('#EditGalleryForm').on('submit', function(e) {
alert($('#EditGalleryForm').attr('action'));
//I added this trying to fix but no luck.
e.PreventDefault();
});
return false;
}
}
},
hide: {
fixed: true,
delay: 100
},
style: 'wiki'
});
$(this).qtip('click', true);
});
形式
<form id="EditGalleryForm" action="Crowork.Backend/Crowork.EditGallery.php?action=DoEditGallery&gallerykey=<?php echo $GalleryData['GalleryID']?>" method="post">
<table border="0" width="100%">
<tr>
<td colspan="2" align="center"><font size="-1"><b>NOTE:</b> Letters & Numbers Only</font></td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="GalleryName" size="30" value="<?php echo $GalleryData['GalleryName']?>"></td>
</tr>
<tr>
<td align="right" colspan="2">
<input type="hidden" name="OriginalGalleryName" value="<?php echo $GalleryData['GalleryName']?>">
<input type="hidden" name="GalleryID" value="<?php echo $GalleryData['GalleryID'] ?>">
<input id="EditGallerySubmit" type="submit" name="EditGallery" value="Edit Gallery">
</td>
</tr>
</table>
</form>
我认为您正在使用提交按钮附加提交事件。附加表单id以提交事件
$('#EditGalleryForm').on('submit', function (e) {
e.preventDefault();
});
我认为这可能会帮助您尝试单击按钮标记上的onclick=“e.preventDefault();”,看看它是否能阻止提交。尝试返回false;在SubmitHandler中,您的表单id是什么?我在帖子中添加了我的html代码。我已经试过返回false。我现在就试试onclick。FormID=EditGalleryForm SubmitButtonID=EditGallerySubmitI刚刚尝试了onclick方法,它仍然加载操作页面。这是一个奇怪的问题。我非常感谢你的时间,我尝试了你的方法,但仍然得到同样的结果。它应该会起作用。您认为问题可能是一个qtip工具提示中的两个默认值?第一个用于href,因此工具提示在鼠标悬停时加载,而不是单击时加载,第二个是在工具加载表单后加载,因此它在工具提示“将提交事件附加到提交”按钮内处理表单提交。而是将事件附加到表单。尝试上面的答案问题出在我的成功函数中,e.preventDefault()带有大写的P。。我把它改成小写的p,它解决了这个问题。我非常感谢你的帮助。