-1

Please does anyone know the script that can help me highligh the content of a textfield on the first click

on the second click the selection / highligh should be cleared from the text box leavingg the insertion point.

Thank You in ADvance..

4

3 回答 3

3

该脚本在第一次单击时选择文本,但在每次连续单击后,textarea 的行为就像 textarea 一样。当文本区域由于模糊事件而失去焦点并再次单击它时,文本将再次被选中。

JsFiddle 上的现场演示

(function () {
    var area = document.querySelector('#txt'),
        clicked = false;

    area.addEventListener('click', function () {
        if (!clicked) {
            area.select();
            clicked = true;
        }
    });

    area.addEventListener('blur', function () {
        clicked = false;
    });    
})()

由于addEventListenerquerySelector示例不完全跨浏览器兼容。

于 2013-01-08T19:18:08.377 回答
1

    function SelectText(sender) {
        document.getElementById(sender.id).focus();
        document.getElementById(sender.id).select();
    }        
<input type="text" id="tbTest" value="Test" onclick="SelectText(this)" />

于 2013-01-08T19:15:14.933 回答
1

试试这个:http: //jsfiddle.net/4Hkhx/1/

$(document).ready(function(){
  $('input').click(function(){
    $(this).select();
  });
});
于 2013-01-08T19:15:25.657 回答