这可能很简单,但是谁能告诉我如何让光标在页面加载时在文本框上闪烁?
当前回答
为什么每个人都用jQuery来做这么简单的事情。
<body OnLoad="document.myform.mytextfield.focus();">
其他回答
$(" #搜索”).focus ();
你也可以使用HTML5 element <autofocus>
这是我更喜欢使用的:
<script type="text/javascript">
$(document).ready(function () {
$("#fieldID").focus();
});
</script>
你可以使用HTML5自动对焦。你不需要jQuery或其他JavaScript。
<input type="text" name="some_field" autofocus>
注意这在IE9及更低版本上不起作用。
肯定的:
<head>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#myTextBox").focus();
});
</script>
</head>
<body>
<input type="text" id="myTextBox">
</body>
实现这一目标的最简单和最简单的方法
$('#button').on('click', function () {
$('.form-group input[type="text"]').attr('autofocus', 'true');
});
推荐文章
- 使伸缩项目正确浮动
- Babel 6改变了它导出默认值的方式
- 如何配置历史记录?
- ES6模板文字可以在运行时被替换(或重用)吗?
- [Vue警告]:找不到元素
- 可以在setInterval()内部调用clearInterval()吗?
- AngularJS控制器的生命周期是什么?
- 无法读取未定义的属性“msie”- jQuery工具
- 形式内联内的形式水平在twitter bootstrap?
- 我的蛋蛋怎么不见了?
- JavaScript中的排列?
- 自定义元素在HTML5中有效吗?
- JavaScript中有睡眠/暂停/等待功能吗?
- 如何触发自动填充在谷歌Chrome?
- jQuery:执行同步AJAX请求