我有这个小函数:
function exeForm(option, pageToLoad, optionId) {
var frm = document.getElementById("frmSessionForm");
var frmOpt = document.getElementById("frmSessionOption");
var frmOptId = document.getElementById("frmSessionOptionId");
frm.action = pageToLoad;
frmOpt.value = option;
frmOptId.value = optionId;
frm.submit();
}
每当我点击链接时都应该调用该函数。但那不会发生。这是我的HTML代码:
<li><a href="#">Card</a>
<ul>
<li><a href="#foo" onclick="exeForm(0,'CardManage.jsp',0);"></a>Search</li>
<li><a href="#foo" onclick="exeForm(1,'CardManage.jsp',0);"></a>Confirm</li>
<li><a href="#foo" onclick="exeForm(2,'CardManage.jsp',0);"></a>New</li>
</ul>
</li>
怎么了?
答案 0 :(得分:0)
只需将文字放在元素中,如
<a href="#foo" onclick="exeForm(0,'CardManage.jsp',0);">Search</a>
答案 1 :(得分:0)
这应该有效:
<!DOCTYPE html>
<html>
<head>
<script>
function exeForm(option, pageToLoad, optionId) {
alert("Inside function");
var frm = document.getElementById("frmSessionForm");
var frmOpt = document.getElementById("frmSessionOption");
var frmOptId = document.getElementById("frmSessionOptionId");
frm.action = pageToLoad;
frmOpt.value = option;
frmOptId.value = optionId;
frm.submit();
}
</script>
</head>
<body>
<li><a href="#">Card</a>
<ul>
<li><a href="#foo" onclick="exeForm(0,'CardManage.jsp',0);">Search</a></li>
<li><a href="#foo" onclick="exeForm(1,'CardManage.jsp',0);">Confirm</a></li>
<li><a href="#foo" onclick="exeForm(2,'CardManage.jsp',0);">New</a></li>
</ul>
</li>
</body>
</html>