此语句没有给我在 selectonemenu 框中选择的值:
document.getElementById("purchaseOrderForm:supplierName").value;
怎么做?
此语句没有给我在 selectonemenu 框中选择的值:
document.getElementById("purchaseOrderForm:supplierName").value;
怎么做?
似乎对我有用
<form>
<select id="purchaseOrderForm:supplierName">
<option value="value 1">value 1 </option>
<option value="value 2">value 2 </option>
<option value="value 3">value 3 </option>
</select>
<input type="button" id="btn_showValue" value="show value"/>
</form>
document.getElementById("btn_showValue").onclick = function(){
console.log(document.getElementById("purchaseOrderForm:supplierName").value)
}
您可以尝试以下方法。例子
HTML
<form>
<select id="purchaseOrderForm:supplierName">
<option value="1">Order 1 </option>
<option value="2">Order 2 </option>
<option value="3">Order 3 </option>
</select>
<input type="button" id="submit" value="submit" onclick="getvalue();"/>
</form>
Javascript
function getvalue()
{
var e = document.getElementById("purchaseOrderForm:supplierName");
var str = e.options[e.selectedIndex].value; //the value of the selected option
alert(str);
var e = document.getElementById("purchaseOrderForm:supplierName");
var str = e.options[e.selectedIndex].text; //the text of the selected option
alert(str);
}