我正在尝试在JavaScript函数内使用组合框中的内容为razor变量分配值。像这样:
<script type ="text/javascript">
<!--
function SomeFunction() {
var hours = document.getElementById("Hours");
var task = document.getElementById("TaskType_ID");
@{
var tsk = @:task.value;
}
@{
<text>
hours.value = '@ViewBag.TaskTypes.GetHours(tsk)';
</text>
}
return true;
}
//-->
</script>
这行代码(以及我尝试的其他变体)
var tsk = @:task.value;
会导致错误。