Disable submit functionality for all forms on a HT

2020-03-12 03:57发布

Using the .NET Windows Forms WebBrowser control to show the preview of a page, I'm using the following approach described in this SO posting to disable all links on the page:

$(function() {
    $('a').click(function() {
        $(this).attr('href', 'javascript:void(0);');
    });
});

Since the HTML page I want to show as the preview also contains HTML forms, I'm looking for a similar approach to disable all form submit functionality.

I've tried:

$(function() {
    $('form').attr('onsubmit', 'return false');
});

But it seems that this doesn't work (read: "still loads the page") for a form like:

<form id="myform" name="myform" onsubmit="return search()" action="">

which I have on the page.

So my question is:

What is the best way to disable all form submit functionality on a HTML page, no matter whether it is a GET or a POST form?

7条回答
闹够了就滚
2楼-- · 2020-03-12 04:24

Use this:

<form id="myform" name="myform" onSubmit="search();return false;" action="">
查看更多
登录 后发表回答