iphone中點擊input不能選中input中的內容


點擊一個input,通過它的click事件選中這個input框中的內容,這個用jquery挺好實現的,但是有一個問題,在PC端和android手機上都可以讓功能正常實現,在iphone上就沒有效果了,后查了好多資料發現在iphone中可以這樣寫

<script>

$(function(){

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

  /*******用以下三行代碼即可實現*******/

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

$(this).focus().select();//保險起見,還是加上這句。

    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;
    });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM