标记div的替代方法

Nor*_*man 0 html jquery

我可以用另一种方式标记我的div,以实现我在这里尝试做的事情.我有这个称为错误的主要div,它将显示所有错误消息.问题是,我的表单输入区域和其他指令文本之间需要介入,因为错误消息和文本需要出现在它们下面.当我做一个$('#errors div').empty();所有的指令文本和其他内容被清除,因为它全部在<div id="errors">任何替代方式标记这3个div(eUname,ePwd,eMail)所以它仍然在标签"错误"?

<div id="form">
  <div id="errors">
     //Input field and other instruction text goes here with its own id
  <div id="eUname"></div>
    //Input field and other instruction text goes here with its own id
  <div id="ePwd"></div>
    //Input field and other instruction text goes here with its own id
  <div id="eMail"></div>
 </div>
</div>
Run Code Online (Sandbox Code Playgroud)

就像是:

<div id="errors" id="eUname" ></div>
Run Code Online (Sandbox Code Playgroud)

Rya*_*nal 5

您可能希望class="error"在所有错误div上使用.

<div id="form">
    <div class="error" id="eUname">Error here</div>
    <div class="error" id="ePwd">Error here</div>
</div>
Run Code Online (Sandbox Code Playgroud)

这意味着您可以像这样使用jQuery:

$('.error').empty();
Run Code Online (Sandbox Code Playgroud)

在相关的说明中,您可以考虑通过htmlDog中的一些教程