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

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

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

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

  當然解決方法很簡單,在創(chuàng)建時,使用document.createElement("<input name='select'>")。不過還不知道是什么原因?
  在Name屬性的說明中有這樣一句話:
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)文章

最新評論