使用jQuery使元素无法选择 [英] Making an element unselectable using jQuery

查看:80
本文介绍了使用jQuery使元素无法选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我知道你可以使用 onselectstart =return false; ondragstart =return false;在HTML中,但我不确定跨浏览器兼容性如何。



我也看到有人的做了一个jQuery插件: http://plugins.jquery.com/project/Unselectable ..是否有必要的插件?



是否有一种简单的兼容方法可以使元素不可选?



想要做到这一点的原因纯粹是美学。使用拖拽或点击事件的网页,当事物被选中时,并不是很好。

('.noselect')。live('selectstart dragstart',function(evt){evt.preventDefault(); return false;});



只需将活动绑定到活动,并返回false或防止默认设置。


What's the best way to make an element unselectable using jQuery?

I know you can use onselectstart="return false;" ondragstart="return false;" in the HTML, but I'm not sure how cross browser compatible that is.

I also see someone's made a jQuery plugin: http://plugins.jquery.com/project/Unselectable .. would a plugin like that be necessary?

Is there a simple, compatible way to make an element unselectable?

The reason for wanting to do this is purely aesthetic. With webpages that have dragging or click events, it's not very nice when things get selected.

解决方案

$('.noselect').live('selectstart dragstart', function(evt){ evt.preventDefault(); return false; });

Just bind the event to a live, and return false, or prevent default.

这篇关于使用jQuery使元素无法选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆