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

iphone中点击input不能选中input中的内容

时间:2017-05-23 21:39:47      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:var   cli   click   code   set   and   oid   end   settime   

点击一个input,通过它的click事件选中这个input框中的内容,这个用jquery挺好实现的,但是有一个问题,在PC端和android手机上都可以让功能正常实现,在iphone上就没有效果了,后查了好多资料发现在iphone中可以这样写

<script>

$(function(){

  //$(‘input‘).focus(focustext)

  /*******用以下三行代码即可实现*******/

  $(‘input‘).click(function(){

    this.selectionStart = 0;

    this.selectionEnd = this.val().length;

  })

})

function focustext() {

  var input = this;

  setTimeout(function(){ input.selectionStart = 0; input.selectionEnd = input.val().length; }, 100)

}

</script>

 

直接用$(‘input‘).click这段代码即可在iphone中实现这个功能,其他代码只是顺带记录一下

 

 

pc和安卓的解决方法:合在一起写

    $(‘.one-goods‘).on("click","input",function () {
        // pc和安卓端的方法
        $(this).focus().select();
        // ios端的方法
        this.selectionStart = 0;
        this.selectionEnd = this.val().length;
    });

 

iphone中点击input不能选中input中的内容

标签:var   cli   click   code   set   and   oid   end   settime   

原文地址:http://www.cnblogs.com/wang715100018066/p/6895988.html

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