相关疑难解决方法(0)

jquery输入在焦点上选择全部

当用户专注于该字段时,我正在使用此代码尝试选择字段中的所有文本.会发生什么,它选择全部一秒钟,然后取消选择,键入光标留在我点击的位置...

$("input[type=text]").focus(function() {
   $(this).select();
});
Run Code Online (Sandbox Code Playgroud)

我希望这一切都保持选中状态.

jquery input

315
推荐指数
8
解决办法
31万
查看次数

获得焦点时选择文本框的所有内容(Vanilla JS或jQuery)

什么是Vanilla JS或jQuery解决方案,当文本框获得焦点时,它将选择文本框的所有内容?

javascript jquery user-interface

302
推荐指数
9
解决办法
28万
查看次数

以编程方式在iOS设备上的输入字段中选择文本(移动版Safari)

如何在iOS设备上以编程方式选择输入字段的文本,例如运行移动Safari的iPhone,iPad?

通常.select(),在<input ... />元素上调用函数就足够了,但这对这些设备不起作用.光标只是留在现有条目的末尾而没有做出选择.

html javascript iphone safari ios

83
推荐指数
5
解决办法
7万
查看次数

selectionStart/selectionEnd输入类型="数字"不再允许在Chrome中使用

我们的应用程序在输入字段上使用selectionStart来确定当用户按下箭头键时是否自动将用户移动到下一个/上一个字段(即,当选择位于文本末尾并且用户按下右箭头时我们移动到下一个字段,否则)

Chrome现在阻止在type ="number"的地方使用selectionStart.它现在抛出异常:

Failed to read the 'selectionStart' property from 'HTMLInputElement': The input element's type ('number') does not support selection.
Run Code Online (Sandbox Code Playgroud)

见如下:

https://codereview.chromium.org/100433008/#ps60001

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#do-not-apply

有没有办法在type ="number"的输入字段中确定插入符的位置?

javascript google-chrome

73
推荐指数
6
解决办法
4万
查看次数

寻找更好的解决方法,Chrome选择焦点错误

我在这个问题中遇到与用户相同的问题,这是由于Webkit中的这个错误.但是,提供的解决方法不适用于我的应用程序.让我重新陈述问题,这样你就不必去读另一个问题了:

我正在尝试选择textarea中的所有文本,当它获得焦点时.以下jQuery代码适用于IE/FF/Opera:

$('#out').focus(function(){
  $('#out').select();
});
Run Code Online (Sandbox Code Playgroud)

但是,在Chrome/Safari中,文本被选中 - 非常简短 - 但随后会触发mouseUp事件并取消选择文本.以上链接提供了以下解决方法:

$('#out').mouseup(function(e){
  e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

但是,这种解决方法对我没有好处.我想在用户给出textarea焦点时选择所有文本.然后,如果他选择,他必须能够只选择部分文本.任何人都可以想到仍然符合此要求的解决方法吗?

javascript jquery webkit

35
推荐指数
2
解决办法
1万
查看次数

.select()函数在iOS设备上不起作用

我想创建一个输入框,当用户选择它时,框中的所有文本都被选中.所以我决定使用这个select()功能,这就是我想要实现的功能.但是,它可以像我预期的那样在桌面浏览器上运行,但不能在iPad上的Safari上运行.如何解决问题?谢谢.

$('#input').click(function(e){
      $(this).select();
});
Run Code Online (Sandbox Code Playgroud)

html javascript mobile jquery mobile-safari

9
推荐指数
1
解决办法
7121
查看次数

使用jQuery在iPhone iPad浏览器中无法选择焦点上的文本

我们正在为移动浏览器开发Web-App,我们希望只要输入框获得焦点,就可以选择任何输入框的文本.以下答案修复了Desktop chrome/safari浏览器的问题.以下解决方案适用于Android浏览器,但不适用于iPhone/iPad浏览器,任何解决方案..

$("#souper_fancy").focus(function() { $(this).select() });

$("#souper_fancy").mouseup(function(e){
        e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

参考: -

使用jQuery在Safari和Chrome中无法选择焦点上的文本

html jquery mobile-website jquery-mobile

5
推荐指数
1
解决办法
2万
查看次数

Safari:焦点事件不适用于按钮元素

焦点事件在单击Safari时在所有浏览器(Safari)上均能正常运行。

而且它在div [tabindex]元素上也可以正常工作,但不适用于button或input:button元素。

当我使用$('。btn')。focus()时,它也可以获取焦点事件。

为什么焦点事件没有在点击时触发?

这是我的代码:

$(".btn").focus(function (e) {
	$(".result").append("<p>Event:"+e.type+", target:"+e.target+"</p>");
})
Run Code Online (Sandbox Code Playgroud)
.result{min-height:200px;border:1px solid #000;}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button class="btn">button 1</button>
<input type="button" class="btn" value="button 2"/>
<div class="btn" tabindex="0">div element</div>
<h1>
Result:
</h1>
<div class="result">

</div>
Run Code Online (Sandbox Code Playgroud)

javascript safari jquery

3
推荐指数
3
解决办法
6162
查看次数

HTML文本输入选择焦点上不在chrome中工作的所有内容

我在表格单元格中有一堆文本输入,如下所示:

<td class="tdTextInput">
    <input type="text" value="0" name="txt1_9_4_2" id="txt1_9_4_2" class="input-supermini">
</td>
Run Code Online (Sandbox Code Playgroud)

每当用户点击单元格或输入时,它必须自动选择输入内的所有内容(有点像电子表格编辑器).

所以这里的脚本到目前为止只能在可靠的旧Firefox中成功实现.

    //focus the textbox on td click
    $('.tdTextInput').mousedown(function ()
    {
        $(this).find('input').first().focus();
    });

    //select all text on focus
    $('.tdTextInput input').focus(function ()
    {
        //the data-selected attribute is used to prevent the 
        // autoselection to happen more than once per cell so that
        // two consecutive  clicks will allow the user to pinpoint the
        // cursor to a specific position
        var isSelected = $(this).attr('data-selected') == 'true';
        if (!isSelected) {
            $('input[data-selected]').removeAttr('data-selected');
            $(this).attr('data-selected', 'true'); …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery focus

2
推荐指数
1
解决办法
6732
查看次数

jquery - 字段选择所有文本然后在焦点上取消选择它

试图弄清楚为什么会发生这种情况 - 我有一个输入文本字段,我想要在字段获得焦点时突出显示所有文本.这很快就会发生,然后所有文本都被取消选中.知道为什么会这样吗?这是我正在使用的代码:

$("#permalink").focus(function(){
    this.select();
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery focus

0
推荐指数
1
解决办法
843
查看次数