On Chromium 7.0.517.44 (64615) Ubun开发者_高级运维tu 10.10, I seem to be unable to change the type attribute of a <button> element:
> blah = document.createElement("button")
<button></button>
> blah.type
"submit"
> blah.type = "button"
"button"
> blah.type
"submit"
Help?
On Firefox 3.6.12 and Opera 10.63, it works fine:
>>> blah = document.createElement("button")
<button>
>>> blah.type
"submit"
>>> blah.type = "button"
"button"
>>> blah.type
"button"
Use setAttribute.
blah.setAttribute('type', 'button');
Change the type attribute on any of the input family generally doesn't work (I know for a fact it does not work on input).
What you may want to do is clone the element, replace the type attribute whilst the HTML is serialised and then append it after. Then delete the original.
======================================================================
javascript:
function submit_button(){
var btn=document.getElementById(button_id');
btn.setAttribute('type', 'submit');
}
======================================================================
Jquery:
function submit_button(){
$('#' + button_id).prop('type', 'submit');
}
======================================================================
here it works.....
加载中,请稍侯......
精彩评论