如何在jQuery UI中获取拖动元素的子元素
问题描述:
我在我的网页上有拖放功能。拖动的div包含2个输入>隐藏,并将其放在另一个div上。如何在jQuery UI中获取拖动元素的子元素
在drop事件中,我想获取两个输入>隐藏在变量中的值。
下面是我的可拖动结构。
<div class="srcfield" title="Drag and map Last Name!">
<span><img src="images/cursor1.png" height="14" width="14" border="0"/> First Name</span>
<input type="hidden" name="FieldName" value="FirstName"/>
<input type="hidden" name="SourceType" value="B"/>
当我这样做:
ui.draggable.children("input").attr("name")
它给了我第一个隐藏字段只。
如何才能得到2隐藏场
感谢 WK
答
首先,你的HTML是不正确的。
其次ui.draggable.children("input")
不是一个单一的元素,.attr("name")
是不值。如果你想获取的值,你必须遍历ui.draggable.children("input").attr("name")
和使用.val()
例如:
ui.draggable.children("input").each(function(){
alert($(this).val());
});
如果你想只得到一个特定的值,考虑增加类的投入和解决这些问题由那个班。有关使用功能的更多信息,请检查jQuery's docs