2015-08-28 15 views
0

使用select元素在我的应用程序,我们使用这个模式很多:停用文本选择,并与Firefox 40

<select name="select" onfocus=this.select; onClick=this.focus();> 
 
    <option value="value1" selected>Value 1</option> 
 
    <option value="value2">Value 2</option> 
 
</select> 
 

 
<script> 
 
document.onmousedown = new Function("return false"); 
 
</script>

线document.onmousedown = new Function("return false");旨在防止页面文本选择。不幸的是,它也阻止了mousedown事件传播到select元素。我们使用的workarround是回调onfocus=this.select; onClick=this.focus();

我的问题是,它不适用于Firefox 40:单击选择框什么也不做。 (与39正常工作)

我可以删除行document.onmousedown = new Function("return false");来修复选择框,但它会允许在页面中选择文本。

我的问题是:我有哪些选项可以同时使用Firefox 40和工作选择框?

+0

你不能只使用CSS? '-moz-user-select:none;用户选择:无;(和任何必需的供应商前缀) – CodingIntrigue

+0

@Rraham Thx,我将重点关注如何处理select元素以搜索其他方式...... –

回答

1

您可以使用CSS。

.noselect { 
    -webkit-touch-callout: none; 
    -webkit-user-select: none; 
    -khtml-user-select: none; 
    -moz-user-select: none; 
    -ms-user-select: none; 
    user-select: none; 
} 

然后应用noselect类(或任何你想将它命名)到其文本你不想为可选择的任何元素。

请参阅this question讨论在不同浏览器中支持这些不同css属性。