为什么不能更改要提交的输入元素的类型? [英] Why can't I change the type of an input element to submit?
本文介绍了为什么不能更改要提交的输入元素的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在调用此函数:
function submit_button(button_id){
$('#' + button_id).attr('type', 'submit');
}
要使此按钮类型=提交而不是按钮.:
to make this button type = submit instead of button.:
<input name="confirm_button" id="confirm_button" type="button" value="Confirm" class="login_btn" />
,我收到此错误(在Firefox中):
and I get this error (in firefox):
未捕获的异常:type属性无法更改
uncaught exception: type property can't be changed
有什么解决方法吗?
推荐答案
function submit_button(button_id){
$('#' + button_id).prop('type', 'submit');
}
请注意,这会更改类型,但不会更改值,因此按钮仍将显示为确认".
Be aware that this changes the type but not the value, so the button will still read "confirm".
证明它的小提琴: http://jsfiddle.net/qeUxP/
这篇关于为什么不能更改要提交的输入元素的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文