How to set button type from JavaScript to avoid exception in ipad's safari?

匆匆过客 提交于 2020-01-14 03:53:17

问题


I do this:

var b = document.createElement('button');
try{
    b.type = 'button';
}catch(e){
    alert(e);
}

On ipad's safari (ios 6.0) the alert shows 'TypeError: Attempted to assign to readonly property.'

Works well in Firefox (no exception). What would be the cross-browser way of doing this from JavaScript? I guess I have to set the button type, according to W3C and MDN, because the default type is usually 'submit', and I want type 'button'.

-- EDIT --

b.setAttribute('type','button') works, but so does b.setAttribute('typo','button'). I've submitted a follow-up question.

来源:https://stackoverflow.com/questions/12881229/how-to-set-button-type-from-javascript-to-avoid-exception-in-ipads-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!