2011-12-31 150 views
2

我在我的網頁上有拖放功能。拖動的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"/>&nbsp;&nbsp;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

回答

3

首先,你的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

相關問題