Struts JSP代码:
<s:select label="Select a Database" headerKey="-1" headerValue="Select database"
list="#{'MySQL':'MySQL', 'Microsoft SQL Server':'Microsoft SQL Server',
'Oracle':'Oracle', 'PostgreSQL':'PostgreSQL'}"
name="dbname" id="databaseType" />
<s:submit value="Submit" onclick="submitDB()" />
javascript代码:
function submitDB() {
var dbname = document.getElementById("databaseType").value;
}
您可以将
select
元素传递给函数
onclick="submitDB(this.form['dbname'])"
然后在函数中使用它来获取值
function submitDB(el) {
val = el.options[el.selectedIndex].value;
}