【发布时间】:2015-05-06 10:14:02
【问题描述】:
在下面的 Struts 标记代码中,我需要在根据从操作传递的值呈现页面之前更改选择中的选定值。但是我找不到获取选项值并对其进行操作的方法。
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html:form action="searchMusic" method="POST">
<html:select property="searchType">
<html:option value="CLASSICAL">CLASSICAL</html:option>
<html:option value="ROCK">ROCK</html:option>
</html:select>
<html:submit value="Search"/>
</html:form>
我尝试了以下功能,但它不起作用。
$(document).ready(function() {
var viewRockOrClassical = '${viewRockOrClassical}';
if (!isEmpty(viewRockOrClassical)) {
var searchBy = document.getElementByName("searchType");
if (viewRockOrClassical == "ROCK") {
searchBy.value = "ROCK";
}
}
});
function isEmpty(str) {
return (!str || 0 === str.length);
}
我在页面加载时遇到的错误是
Uncaught TypeError: undefined is not a function
这是由 "document.getElementByName("searchType")" 行引起的。
【问题讨论】:
标签: jsp struct jsp-tags taglib