Setting name of DOM-created element fails in IE — workaround?

后端 未结 2 1857
既然无缘
既然无缘 2020-12-19 21:33

I got bit hard by this today:

function mk_input( name, val ) {
    var inp = document.createElement( \'input\' );
    inp.name = name;
    inp.value = val;
          


        
2条回答
  •  暖寄归人
    2020-12-19 21:58

    They fixed this in IE8. In previous versions, you need to include the name when you call createElement. From MSDN:

    Internet Explorer 8 and later can set the NAME attribute at run time on elements dynamically created with the IHTMLDocument2::createElement method. To create an element with a NAME attribute in earlier versions of Internet Explorer, include the attribute and its value when using the IHTMLDocument2::createElement method.

    Here is the example from MSDN:

    var newRadioButton = document.createElement("")
    

提交回复
热议问题