我面临的问题是,运行此代码时,代码可以正常工作,直到我在脚本 #option.onclick(vise()); 之间添加这行代码。我想做的工作是,当单击创建选项或选择任何选项时,我想调用该函数,但是当添加此行时,整个事情都会停止工作。
<html>
<head><head>
<body>
<script type="text/javascript">
var jScriptArray=[];
@{
for(int i = 0; i < ViewBag.userClass.Count; i++)
{
<text>jScriptArray[@i] = "@ViewBag.userClass[@i].username";</text>
}
}
var select = document.getElementById("global");
for (var i = 0; i < jScriptArray.length; i++)
{
var option = document.createElement("OPTION"),
txt = document.createTextNode(jScriptArray[i]);
option.appendChild(txt);
option.onclick(vise()); #Error Generator
option.setAttribute("value", jScriptArray[i]);
select.insertBefore(option, select.lastChild);
}
function vise() {
console.log("hello world.");
}
</script>
<form action="DeleteUser" method="post" class="form-horizontal">
<div class="control-group">
<label class="control-label">Username :</label>
<div class="controls">
<select id="global" name="username">
<option value="default">Select</option>
</select>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Save</button>
</div>
</form>
</body>
</html>
ITMISS
相关分类