6 回答

TA貢獻1784條經驗 獲得超9個贊
this,指當前的onclick所在的節點本身。
比如:
1 | <div onclick='select( this )"></div> |
則當點擊div時,this就是div這個dom節點。

TA貢獻1801條經驗 獲得超16個贊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | //select中的onchange是在下拉框中所選的值發生變化時觸發的事件。 //可以給onchange事件綁定一個方法,在onchange事件觸發時會執行綁定的方法。
//示例: //首先可以響應select的onchange事件來調用JS編寫的事件響應函數,如 <select id="select1" name="select1" onchange="outputSelect();"> <option>... </select> //然后編寫事件響應函數: //如果select位于表單(form1)中,select的name為select1,則可使用如下方法: //獲得用戶選中的項的索引 var index=window.document.form1.select1.selectedIndex; //根據索引獲得該選項的value值 var val=window.document.form1.select1.options[index].value; //如果select并非表單元素,假設select的id為select1,則如下: var index=window.document.getElementByIdx_xx_x("select1").selectedIndex; var val=window.document.getElementByIdx_xx_x("select1").options[index].value; //如果要輸出選擇結果,假設HTML中定義了一個<div id="output"></div>,則如下輸出: window.document.getElementByIdx_xx_x("output").innerText=val; //一個示例: function outputSelect(){ //獲取用戶選中的項的索引 var index=window.document.getElementByIdx_xx_x("select1").selectedIndex; //根據index獲取選中項的value值 var val=window.document.getElementByIdx_xx_x("select1").options[index].value; //根據index獲取選中項的Text值,即在下拉列表中顯示的選項文本 var vname=window.document.getElementByIdx_xx_x("select1").options[index].text; //輸出value : textdocument.getElementByIdx_xx_x("output").innerText=val " : " vname; |
添加回答
舉報