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

后端 未结 11 1543
深忆病人
深忆病人 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 13:02

    Based on this post and its comments: http://cf-bill.blogspot.com/2006/03/another-ie-gotcha-dynamiclly-created.html

    the following works. Apparently the problem is that you can't dynamically set the name property in IE. I also found that you can't dynamically set the checked attribute either.

    function createRadioElement( name, checked ) {
        var radioInput;
        try {
            var radioHtml = '

提交回复
热议问题