问题
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