码迷,mamicode.com
首页 > 其他好文 > 详细

input 编辑框 光标 的相关问题

时间:2018-04-13 20:30:49      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:highlight   remove   清除   name   col   ado   编辑   settime   UNC   

 input编辑框 光标 的位置

function set_text_value_position(obj, spos){  
    var tobj = document.getElementById(obj);  
    if(spos<0)  
            spos = tobj.value.length;  
    if(tobj.setSelectionRange){ //兼容火狐,谷歌  
            setTimeout(function(){  
                tobj.setSelectionRange(spos, spos);  
                tobj.focus();}  
                ,0);  
    }else if(tobj.createTextRange){ //兼容IE  
            var rng = tobj.createTextRange();  
            rng.move(‘character‘, spos);  
            rng.select();  
    }  
}  
//调用演示  
set_text_value_position(‘login_div‘, -1);  //设置到末尾  
set_text_value_position(‘login_div‘, 0); //设置到开头 

   input编辑框 清除光标

方法一:(只读,焦点)
<input  name="rulesNo"  readonly="readonly" unselectable="on"/>

方法二:一种是直接设置input的disabled属性。disabled 属性规定应该禁用 input 元素。
 <input type="text"  disabled="disabled" />

方法三:就是input聚焦时马上让它失去焦点,这样可以规避光标显示了。
$(‘input[readonly]‘).on(‘focus‘, function() {
    $(this).trigger(‘blur‘);
});

   input编辑框 获取焦点 失去焦点

获取焦点 行内:
<input type="text" onfocus="txtfocus()" />

失去焦点 行内:
<input type="text" onBlur="txtblur()">

 $("input").focus(function(){
     $(this).addClass("bor");
  });
 $("input").blur(function(){
      $(this).removeClass("bor");
  });

  

 

input 编辑框 光标 的相关问题

标签:highlight   remove   清除   name   col   ado   编辑   settime   UNC   

原文地址:https://www.cnblogs.com/yangqi1209-com/p/8822669.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!