我正在尝试遍历多个表单并将 attr vhid 值发送到后端的 cgi。问题是警报显示第一个值两次。我非常不擅长 javascript,希望能得到一些帮助。
JavaScript
$(document).ready(function () {
$(".sping").each(function () {
$('form#spingForm').ready(function () { // Form is submitted
var data = $('#vhid').attr('value'); // get device name
alert(data);
});
});
});
HTML
<div class="sping">
<div id="spingResult-1"></div>
<form id="spingForm-1" name="spingForm-1" method="post" action="">
<input id="vhid" type="vhid" name="vhid" value="1" />
</form>
</div>
</div>
<div class="span6"></div>
</div>
<div class="row-fluid">
<div class="span6"><strong>DATA</strong>
<br />
<div class="sping">
<div id="spingResult-2"></div>
<form id="spingForm-2" name="spingForm-2" method="post" action="">
<input id="vhid" type="vhid" name="vhid" value="2" />
</form>
</div>
</div>
<div class="span6"></div>
</div>
</div>