以下代码运行第一个控件罚款,第二个控件失败,尽管完全相同:
if (document.getElementById("employeeID").value == "") {
document.getElementById("lblEmp").textContent = "Employee Name is required";
ret = false;
} else {
document.getElementById("lblEmp").textContent = "";
}
if (document.getElementById("grossSalary").value == "") {
document.getElementById("lblGrossSalary").textContent = "Gross Salary is required";
ret = false;
} else {
document.getElementById('#lblGrossSalary').textContent = "";
}
代码正在按预期运行employeeID
控件,但在grossSalary
控件上抛出主题错误。
剃刀:
<div class="form-group">
@Html.LabelFor(model => model.employeeID, htmlAttributes: new { @class = "control-label col-md-2" })
<div id="inner" class="col-md-10">
@Html.EditorFor(model => model.employeeID, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.employeeID, "", new { @class = "text-danger" })
<label id="lblEmp" style="color:red"></label>
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.grossSalary, htmlAttributes: new { @class = "control-label col-md-2" })
<div id="inner" class="col-md-10">
@Html.EditorFor(model => model.grossSalary, new { htmlAttributes = new { @class = "form-control"} })
<label id="lblGrossSalary" style="color:red"></label>
</div>
</div>
答案 0 :(得分:2)
应该是
document.getElementById('lblGrossSalary').textContent = "";
而不是
document.getElementById('#lblGrossSalary').textContent = "";
在你的最后一个块中
答案 1 :(得分:1)
看起来问题可能如下:
else {
document.getElementById('#lblGrossSalary').textContent = "";
}
将('#lblGrossSalary')
更改为('lblGrossSalary')
。
答案 2 :(得分:0)
你只能在对象上使用点(。)运算符,所以如果它是undefined或null并且想要&#34; .value&#34;你会收到一个错误。
我重新编写了你的代码,但这应该适合你!它也更清洁:)
Error: unable to load the file libsbmlj.jar. It is likely
your LD_LIBRARY_PATH environment variable or CLASSPATH variable
does not include the directory containing the libsbmlj.jar file.