2012-01-11 75 views

回答

1

您不能直接傳遞價值的處理程序,但你可以得到它的值,我ð建議做這個代碼,而不是使用內聯事件處理程序:

var select = document.forms[0].sel; 
select.onchange = function(){ 
    var value = select.options[select.selectedIndex].value; // to get Value 
    var text = select.options[select.selectedIndex].text; // to get Text 
} 

這裏有一個工作示例:

http://jsfiddle.net/c2SrV/

0

this.options[this.selectedIndex].value

*假設你想要把它內嵌了onchange屬性

1
<html> 
<head> 
<script> 
function split(value) 
{ 
    alert(value); 
} 
</script> 
</head> 
<body> 
<form> 
<SELECT NAME="sel" onChange="split(value)"> 
<OPTION VALUE=1>Milk</option> 
<OPTION VALUE=2>tea</option> 
<OPTION VALUE=3>water</option> 
<OPTION VALUE=4>coffee</option> 
</SELECT> 
</form> 
<body> 
</html> 

使用 「值」 裏面。希望這是有幫助的

2

不,我怎麼你在這裏做的事情(在A面的標籤)同意,技術上是可以做到的,你通過以下問:

<form> 
<SELECT NAME="sel" onChange="split(this.value)"> 
<OPTION VALUE=1>Milk</option> 
<OPTION VALUE=2>tea</option> 
<OPTION VALUE=3>water</option> 
<OPTION VALUE=4>coffee</option> 
</SELECT> 
</form> 
相關問題