开发者

How to disable dragging with mouse click any images?

I have an image <img src="fullsc开发者_JAVA百科reen.jpg" /> for online driving exams, where the questions are asked using image text and with image embedded. When anyone click the image and drag the mouse it moves the image.

But how can i stop this dragging? So that nobody is allowed to do so.


$('#id-of-your-image').mousedown(function(){return false});

Of course you may have to use other selector as in your example image has no id attribute.


If you're using jQuery, you're looking for the dragstart event.

$("img").bind('dragstart', function(){
    return false; 
});


Try any of these 3 if you can't or don't want to use an id or jQuery (cross-browser performance has not been tested):

<img src="http://www.google.com/intl/en_com/images/srpr/logo3w.png" ondragstart='return false;'/>
<img src="http://www.google.com/intl/en_com/images/srpr/logo3w.png" onmousedown='return false;'/>
<img src="http://www.google.com/intl/en_com/images/srpr/logo3w.png" onmousedown='return false;' ondragstart='return false;'/>

Demo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜