欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript createElement()創(chuàng)建input不能設(shè)置name屬性的解決方法

 更新時(shí)間:2009年10月11日 14:05:27   作者:  
今天在使用document.createElement()動(dòng)態(tài)創(chuàng)建input時(shí),發(fā)現(xiàn)不能為其name賦值,以下是測(cè)試代碼。
其中obj.name = "select";這句話并不能起到預(yù)期的作用,無(wú)論是看生成后的HTML代碼還是觀察使用document.getElementsByName()獲取的數(shù)組長(zhǎng)度,都會(huì)發(fā)現(xiàn)這個(gè)name設(shè)置并沒(méi)有起作用。當(dāng)然這種情況只出現(xiàn)在IE6和IE7中,而在FireFox中是沒(méi)有問(wèn)題的。

[Ctrl+A 全選 注:引入外部Js需再刷新一下頁(yè)面才能執(zhí)行]

  當(dāng)然解決方法很簡(jiǎn)單,在創(chuàng)建時(shí),使用document.createElement("<input name='select'>")。不過(guò)還不知道是什么原因?
  在Name屬性的說(shuō)明中有這樣一句話:
In Internet Explorer 5, the name property cannot be set at run time on anchor objects dynamically created with the createElement method. To create an anchor with a NAME attribute, include the attribute and value when using the createElement method, or use the innerHTML property.

相關(guān)文章

最新評(píng)論