禁用HTML页面上所有表单的提交功能 [英] Disable submit functionality for all forms on a HTML page
问题描述
使用 .NET Windows Forms WebBrowser
控件来显示页面的预览,我使用这张贴子禁用页面上的所有链接:
$(function(){
$('a')。click(function(){
$(this)。 attr('href','javascript:void(0);');
});
});
由于我想显示为预览的HTML页面也包含HTML表单,因此我正在寻找类似的方法来禁用所有表单提交功能。
我试过了:
$(function(){
$('form')。attr('onsubmit','return false');
});
但是这似乎不起作用(请阅读:仍然加载页面)表单如下:
< form id =myformname =myformonsubmit =return search()action = >
我在页面上。
所以我的问题是:
禁用HTML页面上所有表单提交功能的最佳方法是,无论它是否为GET或POST表单?
您应该可以做到:
$( '形式')提交(假);
从 jQuery文档:
lockquote
在jQuery 1.4.3中,您现在可以传入false来代替事件
处理程序。这将绑定一个相当于以下事件处理函数:function(){
return false; }。这个函数可以在以后被
调用:.unbind(eventName,false)。
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?
You should be able to do:
$('form').submit(false);
From the jQuery documentation:
In jQuery 1.4.3 you can now pass in false in place of an event handler. This will bind an event handler equivalent to: function(){ return false; }. This function can be removed at a later time by calling: .unbind( eventName, false ).
这篇关于禁用HTML页面上所有表单的提交功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!