jQuery 将类型属性从提交更改为按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16230518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:44:39  来源:igfitidea点击:

change type attribute from submit to button?

javascriptjquery

提问by av1000

How to change the type attribute from submitto buttonusing JavaScript or jQuery? I use an inputelement like <input type="submit" name="submitform"/>.

如何从改变类型属性submitbutton使用JavaScript或jQuery的?我使用input<input type="submit" name="submitform"/>.

回答by James Allardice

Change the property of the native DOM node:

更改原生 DOM 节点的属性:

document.getElementsByName("submitform")[0].type = "button";

Do it with jQuery:

用 jQuery 来做:

$("input[name='submitform']").prop("type", "button");

But remember that you cannot change inputtypes in Internet Explorer 8 and below.

请记住,您不能input在 Internet Explorer 8 及更低版本中更改类型

回答by rahularyansharma

$('input').prop('type','button');

回答by chandresh_cool

You can use setAttribute property something like this in javascript

您可以在 javascript 中使用类似这样的 setAttribute 属性

document.getElementsByName("submitform").setAttribute('type', 'button');

for jQuery

对于 jQuery

$('input[name="submitform"]').attr("type", "button");

回答by Bogdan M.

Using jQuery:

使用jQuery:

$('input[name="submitform"]').attr('type', 'button');

回答by Zeeshan

For <input type="submit" name="submitform"/>,

对于<input type="submit" name="submitform"/>

write jquery as:

将 jquery 写为:

<script>
$(document).ready(function(){
    $('input[name="submitform"]').attr('type', 'button');
});
</script>

回答by Anh Tú

with jquery:

使用 jquery:

$('input[name="submitform"]').attr('type','button')