如何使用可拖动功能设置检测,当选中该框时,可拖动功能仍无效。
HTML
<div class="drag" style="width:100px; height:100px; background:blue;"></div>
Lock:<input name="lock" id="lock" type="checkbox" value="0" />
JS
if($('#lock').is(':checked') == true){
$(".drag").draggable();
}
答案 0 :(得分:1)
您需要在onchange事件中绑定您的javascript 这是一个小提琴示例http://jsfiddle.net/KPnRc/6/
$(document).ready(function () { // When the document is ready
$('.drag').draggable(); // Initialize the .drag element with draggable
$('#lock').on('change', function (evt) { //Bind a function to the checkbox
if($(this).is(':checked') == true) { //if checked then disable draggable
$('.drag').draggable('disable');
}
else { //else enable draggable.
$('.drag').draggable('enable');
}
});
});