gpt4 book ai didi

javascript - 遍历 div 内的输入

转载 作者:太空狗 更新时间:2023-10-29 16:50:14 27 4
gpt4 key购买 nike

我正在尝试通过 jQuery 遍历放置在特定 div 上的所有输入,但没有任何响应。我无法使用警报查看输入值。我究竟做错了什么 ?

<form id="internshipStage2Form" method="POST" action="form2.php">
<center>
<table id="studentInformation" border="1">
<caption style="color:#f00;">Student(Trainee) Information</caption>
<tr>
<td valign="middle" align="center">
<label id="stuEmailLabel" for="stuEmailText">E-mail Address</label>
</td>
<td valign="middle" align="center"><?php echo $email; ?></td>
</tr>
<tr>
<td valign="middle" align="center">
<label id="stuPhoneLabel" for="stuPhoneText">Phone</label>
</td>
<td><input id="stuPhoneText" type="text" name="stuPhoneText"/></td>
</tr>
</table>
<div id="companyInfo">
<table id="companyInformation" border="1">
<caption style="color:#f00;">Company Information</caption>
<tr>
<td valign="middle" align="center">
<label id="companyNameLabel" for="companyNameText">Company Name</label>
</td>
<td><input id="companyNameText" type="text" name="companyNameText"/></td>
</tr>
<tr>
<td valign="middle" align="center">
<label id="companyAdressLabel" for="companyAdressText">Address</label>
</td>
<td><input id="companyAdressText" type="text" name="companyAdressText"/></td>
</tr>
<tr>
<td valign="middle" align="center">
<label id="companyPhoneLabel" for="companyPhoneText">Phone</label>
</td>
<td><input id="companyPhoneText" type="text" name="companyPhoneText"/></td>
</tr>
<tr>
<td valign="middle" align="center">
<label id="" for="">Did the any students work as trainees in the company in the previous years?</label>
</td>
<td valign="middle" align="center">
Yes<input id="g1Positive" type="radio" name="g1" value="YES"/>
No<input id="g1Negative" type="radio" name="g1" value="NO"/>
</td>
</tr>
</table>
</div>
<h4 style="color:#f00;">
I agree the terms.
</h4>
<input id="stuDecCheckBox" type="checkbox" name="stuDecCheckBox" /></br>
<input id="sendButton" type="submit" name="sendButton2" value="SEND FOR APPROVEMENT"/>
</center>
</form>

JS

$('#companyInfo').children('input').each(function () {
alert(this.value);
});

如有任何帮助,我们将不胜感激。

最佳答案

您的输入不是 #companyInfo 的子项。只需这样做:

$('#companyInfo input').each(function () {
alert(this.value);
});

关于javascript - 遍历 div 内的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24619440/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com