五月综合缴情婷婷六月,色94色欧美sute亚洲线路二,日韩制服国产精品一区,色噜噜一区二区三区,香港三级午夜理伦三级三

您現(xiàn)在的位置: 365建站網(wǎng) > 建站教程 > JavaScript 教程 > HTML DOM add() 方法

HTML DOM add() 方法

此節(jié)有 291 人學(xué)習(xí)過     參與評論

定義和用法

add() 方法用于向 <select> 添加一個(gè) <option> 元素。

語法

selectObject.add(option,before)
參數(shù) 描述
option 必需。要添加選項(xiàng)元素。必需是 option 或 optgroup 元素。
before 必需。在選項(xiàng)數(shù)組的該元素之前增加新的元素。如果該參數(shù)是null,元素添加到選項(xiàng)數(shù)組的末尾。

實(shí)例

下面的例子可向下拉列表的末尾添加一個(gè) "kiwi" 選項(xiàng):

<html>
<head>
<script type="text/javascript">
function insertOption()
  {
  var y=document.createElement('option');
  y.text='Kiwi'
  var x=document.getElementById("mySelect");
  try
    {
    x.add(y,null); // standards compliant
    }
  catch(ex)
    {
    x.add(y); // IE only
    }
  }
</script>
</head>
<body>

<form>
<select id="mySelect">
  <option>Apple</option>
  <option>Pear</option>
  <option>Banana</option>
  <option>Orange</option>
</select>
<input type="button" onclick="insertOption()"
value="Insert option" />
</form>

</body>
</html>

如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會為你解答!! 點(diǎn)擊進(jìn)入論壇

發(fā)表評論 (291人查看,0條評論)
請自覺遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴(yán)禁發(fā)布色情、暴力、反動的言論。
昵稱:
最新評論
------分隔線----------------------------
JavaScript 教程目錄

其它欄目

· 建站教程
· 365學(xué)習(xí)

業(yè)務(wù)咨詢

· 技術(shù)支持
· 服務(wù)時(shí)間:9:00-18:00
365建站網(wǎng)二維碼

Powered by 365建站網(wǎng) RSS地圖 HTML地圖

copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號