什么是香草JS或jQuery解决方案,将选择一个文本框的所有内容时,文本框接收焦点?
当前回答
这个会有用的,试试这个
<input id="textField1" onfocus="this.select()" onmouseup="return false" />
可以在Safari/IE 9和Chrome上运行,但我没有机会在Firefox上测试。
其他回答
我在某个地方播种了这个,工作得很完美!
$('input').on('focus', function (e) {
$(this)
$(element).one('mouseup', function () {
$(this).select();
return false;
}) .select();
});
$(document).ready(function() {
$("input:text").focus(function() { $(this).select(); } );
});
什么是JavaScript或jQuery解决方案,将选择一个文本框的所有内容时,文本框接收焦点?
您只需要添加以下属性:
onfocus="this.select()"
例如:
<input type="text" value="sometext" onfocus="this.select()">
(说实话,我不知道你为什么还需要其他东西。)
onclick="this.focus();this.select()"
HTML:
var textFiled = document.getElementById("text-filed"); 文本文件。addEventListener("focus", function() {this.select();}); 输入你的文本:<input type=" Text " id=" Text -filed" value="test with filed Text ">
使用JQuery:
$("#text-filed").focus(function() { $(this).select(); } );
使用React JS:
在各自的组成部分-
<input
type="text"
value="test"
onFocus={e => e.target.select()}
/>
推荐文章
- 如何将“camelCase”转换为“Camel Case”?
- 我们可以在另一个JS文件中调用用一个JavaScript编写的函数吗?
- 如何使用JavaScript重新加载ReCaptcha ?
- jQuery。由于转义了JSON中的单引号,parseJSON抛出“无效JSON”错误
- 在JavaScript关联数组中动态创建键
- Xcode 10的对象库去哪了?
- ReactJS和公共文件夹中的图像
- 在React Native中使用Fetch授权头
- 为什么我的球(物体)没有缩小/消失?
- 如何使用jQuery检测页面的滚动位置
- if(key in object)或者if(object. hasownproperty (key)
- 一元加/数字(x)和parseFloat(x)之间的区别是什么?
- angularjs中的compile函数和link函数有什么区别
- 删除绑定中添加的事件监听器
- 如何在JSON中使用杰克逊更改字段名