我不明白为什么会出现此错误:TypeError: ui is undefined
然而代码非常简单!演示代码:http: //jsfiddle.net/9sNEK/19/
最终目标是当我拖动绿色 div 时触发红色 div 的拖动
JS
$('.div_green')
.draggable()
.bind('drag',function(event,ui){
$('.div_red').trigger('drag');
$('.log').html("drag green - left:" + ui.position.left);
});
$('.div_red')
.draggable()
.bind('drag', function(event,ui){
$('.log2').html("drag_to_simulate - left:"+ ui.position.left);
});
HTML
<div class="div_green"></div>
<div class="pdrag" id="pdrag1">
<div class="div_red"></div>
</div>
<div class="pdrag" id="pdrag2">
<div class="div_red"></div>
</div>
<div class="log" style="width:200px;height:20px;"></div>
<div class="log2" style="width:200px;height:20px;"></div>
CSS
.div_green, .pdrag, .div_red{
position:absolute;
}
.div_green{
width:40px;
height:40px;
top:170px;
left:300px;
background-color: green;
}
.pdrag{
width:120px;
height:120px;
top:50px;
left:90px;
background-color: #F1F1F1;
}
#pdrag2{
top:230px;
width:150px;
}
.div_red{
width:20px;
height:20px;
top:40px;
left:50px;
background-color:red;
}
#pdrag2 .div_red{
left:75px
}
非常感谢您的帮助。