什麼是管理這種情況的最好辦法:內的每個變化()()jQuery的
$('.element').each(function() {
$sibling = // find a sibling to $this.
$mainElement = $(this); // memorize $(this)
$sibling.change(function() {
// when sibling changes
// do something using $mainElement
// problem is, $mainElement is not the element you think
// $mainElement is the last .element found....
})
});
一個解決方案是一個表......但後來就沒有優勢的變化()被嵌套在各()...
我的HTML例子:
<div id="first">
<span class="element"></span>
<input name="first" type="text" />
</div>
<div id="second">
<span class="element"></span>
<input name="second" type="text" />
</div>
在本例,$sibling = $(this).next('input');
例如。
您是否嘗試過的:var $ =兄弟//找到兄弟姐妹到$這。 var $ mainElement = $(this); – luckystars 2013-02-16 12:11:31
發表html,很抱歉等待。 – Lyth 2013-02-16 15:31:26