html下拉框只读,HTML元素(如select下拉框)设置为只读
其实就是利用了鼠标事件和去焦点功能。
以select下拉框为例:
οnmοuseοut="this.releaseCapture();">
value="optionValue">下拉框文字
onmousemove:鼠标在下拉框范围内活动时触发,调用setCapture函数让span捕获鼠标指针,从而阻止select相应鼠标事件。
onmouseout:鼠标离开下拉框时将鼠标指针的捕获还给当前页面。
onfocus:当select下拉框变成当前焦点时,取消它的焦点。
如果想在JS脚本中实现只读和取消:
加锁:
document.getElementByIdx_x("spanID").onmousemove = function()
{this.setCapture();};
document.getElementByIdx_x("spanID").onmouseout = function()
{this.releaseCapture();};
document.getElementByIdx_x("selectID").onfocus = function()
{this.blur();};
解锁:
document.getElementByIdx_x("spanID").οnmοusemοve="";
document.getElementByIdx_x("spanID").οnmοuseοut="";
document.getElementByIdx_x("selectID").οnfοcus="";
《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读总结
以上是生活随笔为你收集整理的html下拉框只读,HTML元素(如select下拉框)设置为只读的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 任正非谈鸿蒙系统失误,谷歌也没想到会来的
- 下一篇: html border阴影效果_HTML