Javascript onmousedown IE8不工作
我创造了这样的东西Javascript onmousedown IE8不工作,javascript,html,internet-explorer,internet-explorer-8,Javascript,Html,Internet Explorer,Internet Explorer 8,我创造了这样的东西 <textarea id='txtarea'>Dear Sir/Madam Sincerely, [Your Name] </textarea><br/><input id="btn" value='Add Date' type="button"/> <script> var textarea=document.getElementById('txtarea'),pos=0 textarea.fo
<textarea id='txtarea'>Dear Sir/Madam
Sincerely,
[Your Name]
</textarea><br/><input id="btn" value='Add Date' type="button"/>
<script>
var textarea=document.getElementById('txtarea'),pos=0
textarea.focus()
document.getElementById('btn').onclick=addDate
document.getElementById('btn').onmousedown=function(){return false}
function addDate(){
textarea.innerHTML+="\n"+new Date().toUTCString()
}
</script>
尊敬的先生/女士
真诚地
[你的名字]
var textarea=document.getElementById('txtarea'),pos=0
textarea.focus()
document.getElementById('btn')。onclick=addDate
document.getElementById('btn').onmousedown=function(){return false}
函数addDate(){
textarea.innerHTML+=“\n”+新日期().toutString()
}
所有这些代码在除IE8和更低版本之外的所有浏览器上都能正常工作。。。问题是:
当文本区域处于焦点并且用户单击“添加日期”按钮时,无需取消选择文本区域(onmousedown=function(){return false}
)。在IE 8和更低版本中,它被取消选择(我认为返回false
不起作用)
如何支持IE 8及更低版本
这可能有效(未在ie中测试)
在较旧的IEs中,有
不可选择的属性可用。通过将其设置为on
可防止具有该属性的元素接收焦点
<input id="btn" value='Add Date' type="button" unselectable="on" />
我现在找不到任何文档,但是如果我能正确地回忆起来,这个属性需要直接设置为标记,或者可以使用setAttribute()
以编程方式设置。设置不可选择
属性无效
关于……的文章。尽管本文也解释了,当你可以省略分号时,使用分号是最安全的。为什么不使用分号?我很惊讶这能起作用。@nullability,在哪里?
<input id="btn" value='Add Date' type="button" unselectable="on" />