我在剃刀局部视图中有很少的文本框,可根据条件提供。其中1个附加到具有以下代码的自动完成,但是当加载部分视图时,我得到错误(如果文本框不可用)
0x800a138f - JavaScript运行时错误:无法设置属性 ' _renderItem'未定义或空引用
如果文本框在Razor视图中可用,则不会显示错误。
我的Jquery代码是
var noten = new Array();
noten["Gusenbauer"] = new Array();
noten["Gusenbauer"]["1ahitm"] = 0;
noten["seppl"]["1ahitm"] = new Array();
noten["seppl"]["1ahitm"] = 0;
noten["leo"]["1ahitm"] = new Array();
noten["leo"]["1ahitm"] = 0;
noten["Gussenbauer"]["2ahitm"] = new Array();
noten["Gussenbauer"]["2ahitm"] = 0;
noten["steiner"]["2ahitm"] = new Array();
noten["steiner"]["2ahitm"] = 0;
noten["roland"]["2ahitm"] = new Array();
noten["roland"]["2ahitm"] = 0;
alert(noten["roland"]["2ahitm"]);
alert("was");
function noteEintragen() {
var name = document.notenformular.name.value;
alert(name);
var note = document.notenformular.note.value;
var klasse = document.notenformular.klasse.value;
noten[name][klasse] = note;
}
ody>
<div id="wrapper">
<h1>Name - Noteneintragung - Klassenspiegel</h1>
<hr>
<p>Klasse auswählen, Name auswählen, Note eintragen</p>
<form name="notenformular">
Klasse
<br>
<select name="klasse" onchange="java_script_:show(this.options[this.selectedIndex].value)" size="20" tabindex="2">
<option value="1ahitm">1ahitm</option>
<option value="2ahitm">1bhitm</option>
</select>
<br>
<br> Name
<br>
<div id="hiddenDiv" style="display:none">
<select name="name" id="test" size="20" tabindex="1">
<option value="Gusenbauer">Gusenbauer</option>
<option value="seppl">seppl</option>
<option value="leo">leo</option>
</select>
答案 0 :(得分:0)
您应首先检查dom中是否存在文本框:
var txtcompany = $("#txtcompany");
alert(txtcompany.length);
if (txtcompany.length === 1) {
txtcompany.autocomplete({ ...
};