以下是HTML
<div id="serverList" class="content">
<div class="boxtitle">
</div>
<div id='serverInfo1' class="formEl_b">
<fieldset>
<legend>Server #1</legend>
<div class="section">
<label>
Server Description<small>Linux</small></label>
<div>
<input type="text" id="serverDescription" class="serverDescription medium" /><span class="f_help"></span></div>
</div>
<div class="section">
<label>
Server HostName<small>SRV_FR_TERT</small></label>
<div>
<input type="text" id="serverHostName" class="serverHostName medium" /><span class="f_help"></span></div>
</div>
</fieldset>
</div>
<div id='serverInfo2' class="formEl_b">
<fieldset>
<legend>Server #2</legend>
<div class="section">
<label>
Server Description<small>Windows 2003</small></label>
<div>
<input type="text" id="serverDescription" class="serverDescription medium" /><span class="f_help"></span></div>
</div>
<div class="section">
<label>
Server HostName<small>SRV_EQ_SFGT</small></label>
<div>
<input type="text" id="serverHostName" class="serverHostName medium" /><span class="f_help"></span></div>
</div>
</fieldset>
</div>
<div id='serverInfo3' class="formEl_b">
<fieldset>
<legend>Server #3</legend>
<div class="section">
<label>
Server Description<small>iOS</small></label>
<div>
<input type="text" id="serverDescription" class="serverDescription medium" /><span class="f_help"></span></div>
</div>
<div class="section">
<label>
Server HostName<small>SRV_WR_RQRT</small></label>
<div>
<input type="text" id="serverHostName" class="serverHostName medium" /><span class="f_help"></span></div>
</div>
</fieldset>
</div>
</div>
我正在尝试使用 JQuery 迭代上面的 htmldescription
并hostname
为每个服务器打印
$("#serverList").children(".formEl_b").each(function () {
// this is what i am trying to get with no success:
var description = $(".formEl_b .serverDescription").val();
var hostname = $(".formEl_b .serverHostName").val();
alert(description);
alert(hostname);
});
我遇到的问题是它总是打印第一个description
,hostname
甚至有 3 个此类项目。