0

How to set detect with draggable function, When check the box the draggable function still not work.

http://jsfiddle.net/KPnRc/

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();

}
4

1 回答 1

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');
        }
    });
});
于 2012-10-23T00:57:44.063 回答