Iterate through inputs inside of a div(遍历 div 内的输入)
                            本文介绍了遍历 div 内的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
                        
                        问题描述
我正在尝试遍历通过 jQuery 放置在特定 div 上的所有输入,但没有响应.我无法使用警报查看输入的值.我究竟做错了什么 ?
I'am trying to iterate through all inputs which are placed on a specific div via jQuery, but there is no response. I can't see the values of inputs by using alert. What am I doing wrong ?
<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);
});
如有任何帮助,将不胜感激.
Any help would be appriciated.
推荐答案
您的输入不是 #companyInfo 的子级.只需这样做:
Your inputs are not children of #companyInfo. Just do this:
$('#companyInfo input').each(function () {
    alert(this.value);
});
这篇关于遍历 div 内的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
				 沃梦达教程
				
			本文标题为:遍历 div 内的输入
 
				
         
 
            
        
             猜你喜欢
        
	     - 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
 
						 
						 
						 
						 
						 
				 
				 
				 
				