jQuery函数只工作一次Html5自动对焦
jQuery Func Only Works Once Html5 autofocus
我有一个带有搜索栏和这些功能的移动应用程序:
$(".dk").hide(0);
$("#fus").click(function () {
$(".dk").fadeOut(100);
$("#sim").removeAttr("autofocus")
});
$("#ys").click(function (e) {
$("#s,#u,#n,#l,#a,#m,.dk").hide(100);
$("#re,#r").animate({"margin-left": "0px"}, 200);
$("#s,#u,#n").animate({ "margin-left": "2px"}, 200);
$("#sim").delay(300).attr({"autofocus": "autofocus"});
$(".dk").fadeIn(100);
e.stopPropagation();
});
})
HTML
<div style="padding-top:10px;" id="toolbar"> <a href="#" id="open-left"></a>
<div class="tbar">
<img style="height:30px;" src="img/cles.png" />
<div class="ha">
<img id='ys' style=" height:27px" src="img/searchico.png" />
</div>
</div>
</div>
<div class='dk'>
<form id="hif">
<input id='sim' type="search">
<img style="position:absolute;height:26px;margin-left:-270px;margin-top:20px;" src="img/searchicog.png">
</form>
</div>
我正试图淡出div .dk
(又名搜索框)。#Ys
是搜索图标,#sim
是输入字段,#fus
是点击(或点击)触发淡出功能的地方。
遗憾的是它只自动对焦一次。它也搞砸了fadeIn
时,它的工作。之后,我必须刷新页面,让它再次自动对焦。
这个YouTube视频展示了我想要完成的:https://www.youtube.com/watch?v=T5n3m2LRy5Y
设置自动聚焦属性不会导致焦点改变。相反,您应该使用.focus()方法。
$(".dk").hide(0);
$("#fus").click(function () {
$(".dk").fadeOut(100);
$("#sim").removeAttr("autofocus")
});
$("#ys").click(function (e) {
$("#s,#u,#n,#l,#a,#m,.dk").hide(100);
$("#re,#r").animate({"margin-left": "0px"}, 200);
$("#s,#u,#n").animate({ "margin-left": "2px"}, 200);
$("#sim").delay(300).focus();
$(".dk").fadeIn(100);
e.stopPropagation();
});
})
另外,.delay不会延迟非动画,所以要延迟焦点,你需要使用setTimeout。
setTimeout(function(){
$("#sim").focus()
},300)
- Javascript返回值只在循环中返回一次
- Jquery FadeIn FadeOut 只工作一次
- Javascript html每点击一次就会更改url
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- Rails操作只调用一次,但我在ajax中每秒钟都调用一次
- jQuery滚动功能只工作一次
- 我试图用jQuery让每个HTML5元素一次淡出一个
- 如何在HTML5网页中本地保存数据,这样我们就不需要一次又一次地从服务器获取
- html5视频的时间更新事件多久触发一次
- 为什么"结束”;音频html5的事件触发不止一次
- HTML5视频自动播放/播放一次
- 为什么可以't我使用HTML5音频标签播放声音不止一次
- HTML5 -视频播放时每隔几秒触发一次事件
- HTML5-只加载一次视频,但在两个不同的标签中使用
- Javascript, Html5 Canvas渲染一次后,更新它
- 播放HTML5视频时,滚动到,然后播放,直到完成,只播放一次
- 2个音频,我想一次只播放一个HTML5音频元素
- jQuery函数只工作一次Html5自动对焦
- HTML5 文件 API,按顺序包含多个文件,而不是一次全部文件
- HTML5历史API:不能倒退超过一次