输入框--仿placeholder,oninput检测用户输入事件
2016-11-18 19:54
501 查看
user-select: none; /* 禁止选择网页内容 */
完美解决了 和input相配合的label能够选中 问题。
代码中注释部分也可以达到 此效果!
完美解决了 和input相配合的label能够选中 问题。
代码中注释部分也可以达到 此效果!
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> .search{ width: 300px; height: 30px; margin: 100px auto; position: relative; } .search input{ width: 200px; height: 20px; outline-style: none; text-indent: 10px; } .search label{ position: absolute; top: 8px; left:10px; font-size: 12px; color: #666; cursor: text; /* touch-action: none; 禁止触发默认的手势操作 -ms-touch-action: none; pointer-events: none; css3属性,鼠标事件失效 */ -moz-user-select: none; /*火狐*/ -webkit-user-select: none; /*webkit浏览器*/ -ms-user-select: none; /*IE10*/ user-select: none; /* 禁止选择网页内容 */ } </style> <script> window.onload = function(){ function $(id){ return document.getElementById(id);} //oninput 大部分浏览器支持 检测用户表单输入内容 //onpropertychange ie678 检测用户表单输入内容 $('txt').oninput = $('txt').onpropertychange = function(){ // 用户输入触发 if($('txt').value == ""){ $('txtLabel').style.display = "block"; }else{ $('txtLabel').style.display = "none"; } } $('txt').onmouseover = function(){ this.select(); //选中所有文本 } } </script> </head> <body> <div class="search"> <input type="text" id="txt"> <label for="txt" id="txtLabel">必败的品牌</label> </div> </body> </html>
相关文章推荐
- js实现文本框或文本域在用户输入时(oninput)触发事件,操作元素
- jquery实现input输入框实时输入触发事件代码 ---jQuery 中bind(),live(),delegate(),on() 区别
- 同时绑定onpropertychange 和 oninput 事件,实时检测 input、textarea输入改变事件,支持低版本IE,支持复制粘贴
- oninput、onchange与onpropertychange事件的区别, 与input输入框实时检测
- 【学习】文本框输入监听事件oninput
- jquery实现input输入框实时输入触发事件
- JavaScript监听input等表单输入框的变化事件oninput
- js监听input输入框,让用户在使用拼音输入法的状态下无法输入除数字外的任何字符
- 输入框input内容变化与onpropertychange事件的兼容
- easyui textbox 输入小写自动变大写,easyui textbox 绑定oninput事件 easyui textbox 绑定propertychange事件
- HTML5 input事件检测输入框变化[转载]
- #632 – 使用PreviewTextInput事件阻止用户输入(Block Input Using PreviewTextInput)
- input 输入框内的输入事件详细分析
- jquery实现input输入框实时输入触发事件代码
- input框设置onInput事件只能输入数字,能兼容火狐IE9
- 实时监控文本框输入的信息,JS中的oninput & onpropertychange事件
- input输入框file类型选择同样输入框第二次不触发onchange事件的解决办法
- onpropertychange 实时监控input输入框事件实现
- input 输入框内的输入事件详细分析
- js监听input等表单输入框的变化事件oninput