How do you dynamically create a radio button in Javascript that works in all browsers?

后端 未结 11 1520
深忆病人
深忆病人 2020-12-01 12:12

Dynamically creating a radio button using eg

var radioInput = document.createElement(\'input\');
radioInput.setAttribute(\'type\', \'radio\');
radioInput.se         


        
11条回答
  •  抹茶落季
    2020-12-01 12:49

    Patrick's answer works, or you can set the "defaultChecked" attribute too (this will work in IE for radio or checkbox elements, and won't cause errors in other browsers.

    PS Full list of attributes you can't set in IE is listed here:

    http://webbugtrack.blogspot.com/2007/08/bug-242-setattribute-doesnt-always-work.html

提交回复
热议问题