2011-11-02 37 views

回答

7

可以綁定一個變化事件監聽器的select元(假設你的select元素具有yourSelectid):

document.getElementById("yourSelect").onchange = function() { 
    var selected = this.value; 
    //Do whatever with the selected value 
} 

這裏有一個working example。只要select的值發生更改,就會調用onchange事件偵聽器。您可以使用this.value訪問所選選項的value,並將其傳遞到您的服務器端腳本。

0

在醜陋的直接編碼方法:

<select onchange="the_select_was_changed(this);"> 
    <option>...</option> 
    <option>...</option> 
</select> 

function the_select_was_changed(obj) { 
    alert("The selected index is " + obj.selectedIndex + " and has value " + obj.options[obj.selectedIndex]); 
} 
0

添加每個selectboxes事件的onChange:

<select name="{any name}" onChange="myVJsValuecheckFunction(this)"> 
    <option value="{myOptionValueOne}">myoptionText</option> 
    ... 
</select> 

然後編寫JavaScript函數:

function 
相關問題