禁用HTML元素的文本选择
问题描述:
我正在使用jQuery UI函数.disableSelection()
禁用文本选择.虽然它对于<div>
元素可以正常工作,但是我无法让它对<input>
元素起作用.有什么建议吗?
I'm using the jQuery UI function .disableSelection()
to disable text selection. While it works fine for <div>
elements, I can't get it to work for <input>
elements. Any suggestions?
以下是问题的一个示例: http://jsfiddle.net/7SfBx/
Here is an example of the problem: http://jsfiddle.net/7SfBx/
答
假设您要停止选择文本而不是禁用元素,则可以略微修改代码以实现此目的.实时示例: http://jsfiddle.net/7SfBx/2/
Assuming you are looking to stop text selecting rather than disable an element, you can modify your code slightly to achieve this. Live example: http://jsfiddle.net/7SfBx/2/
$('.test').disableSelection().css('webkit-user-select','none');