Jquery功能不起作用

时间:2016-06-01 11:56:31

标签: jquery html

像这样的功能正常工作

$(function() {
    $('#square').udraggable({
    containment: [ 0, 0, 8000, 8000],
    grid:        [ 30, 30 ]
    });
}); 

 <div id="square"></div>

但下面的那个没有。有什么想法吗?感谢

$(function Myfunction (id){
            $("#" + id).udraggable({
                containment: [ 0, 0, 8000, 8000],
                grid: [ 30, 30 ]
            });
        });

<img onclick="Myfunction(this.id)" src="files/pic/googleWebsite.png" id="googleWebsite" height="33">

2 个答案:

答案 0 :(得分:0)

由于定义函数的语法错误,它无法正常工作。只需定义这样的函数:

    function Myfunction(id){
        $("#" + id).udraggable({
            grid: [ 15, 15 ]
        });
    }

答案 1 :(得分:0)

尝试此操作,将onclick更改为onload

function Myfunction (id){
            $("#" + id).udraggable({
                containment: [ 0, 0, 8000, 8000],
                grid: [ 30, 30 ]
            });
        }

<img onload="Myfunction(this.id)" src="files/pic/googleWebsite.png" id="googleWebsite" height="33">