e.PreventDefault在qtip中提交问题


e.PreventDefault submit issue in qtip

我正试图在qtip工具提示中获取我的表单,以便在不加载页面的情况下提交。然而,我似乎无法让它在点击提交后停止加载页面。它在href上运行良好,但在表单中的提交按钮上不起作用。

//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();
});

我认为这可能会帮助您