1

我正在尝试验证 javascript 中的代码。这是我的代码:

if(document.getElementById("name").value == ""){
    alert("Name is a required field");
    document.getElementById("name").focus();
    return false;
}

name在我的 html 页面中是 id:

<div class="app-form-box">
  {% if review %}
    {% if not review.name %}
      <input type="text" alt="" onkeyup="return validateField(name)" tabindex="2" name="name" id="name" class="disabled inputtxtlarge" onfocus="highlightInput(this.id)" onblur="return (!validateField(name) || unhighlightInput(this.id))" maxlength="50" value="{{name|moonescape}}" disabled="disabled"/><span> </span>
    {% else %}
      <input type="text" alt="" onkeyup="return validateField(name)" tabindex="2" name="name" id="name" class="inputtxtlarge" onfocus="highlightInput(this.id)" onblur="return (!validateField(name) || unhighlightInput(this.id))" maxlength="50" value="{{name|moonescape}}"/><span> </span>
    {% endif %}
  {% else %}
    <input type="text" alt="" onkeyup="return validateField(name)" tabindex="2" name="name" id="faname" class="inputtxtlarge" onfocus="highlightInput(this.id)" onblur="return (!validateField(name) || unhighlightInput(this.id))" maxlength="50" value="{{name|moonescape}}"/><span> </span>
  {% endif %}
  <div class="servererror">
    {% if form_errors.name %}
      * {{ form_errors.name|join:"| " }}<br/>
    {% endif %}
  </div>
</div>

但我越来越OBJECT REQUIRED。请建议如何为此检查 js 文件。谢谢

4

0 回答 0