使用jquery在facebox div中获取元素的值 [英] Getting value of an element inside facebox div using jquery
问题描述
我有两个div标签,如下所示在我的页面上。当我引用itemName元素的值,使用 $('#itemName')。val(); 这两个div,我总是获得元素的值在第一个div是(空白)。有没有办法使用jquery获取第二个div中的itemName元素的值?
I have two div tags as shown below on my page. When i reference the value of itemName element,using $('#itemName').val(); which i have in both the divs, i always get the value of the element in the first div which is ""(blank). Is there a way to get the value of the itemName element in the 2nd div i.e. facebox using jquery ?
信息div
<div id="info" style="display: none;">
<center>
<strong>Name</strong>
<input id="itemName" type="text"/>
<br/>
<br/>
<strong>Price </strong>
<input id="itemPrice" type="text"/>
<br/>
<br/>
</center>
</div>
facebox div
facebox div
<div id="facebox" style="top: 27.3px; left: 478px; display: none;">
<div class="popup">
<table>
<tbody>
<tr>
</tr>
<tr>
<td class="b"/>
<td class="body">
<div class="content" style="display: block;">
<div id="info" style="">
<center>
<strong>Name</strong>
<input id="itemName" type="text"/>
<br/>
<br/>
<strong>Price </strong>
<input id="itemPrice" type="text"/>
<br/>
<br/>
<input type="button" onclick="updateTab();" value="Add"/>
</center>
</div>
</div>
谢谢
推荐答案
如果你看看facebox.js,你会看到有一个事件,当facebox打开时触发,所以你只需要绑定到该事件,然后获取值:
If you look inside facebox.js, you'll see that there is an event that is triggered when facebox opens, so you just need to bind to that event, then obtain the value:
$(document).bind('reveal.facebox', function() {
$('#facebox #itemName').val();
})
这篇关于使用jquery在facebox div中获取元素的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!