慕仰6432972
2016-09-10 14:46:13
<!DOCTYPE html><html><head>? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />? ? <title></title>? ? <style>? ? .left div,? ? .right div {? ? ? ? width: 500px;? ? ? ? height: 50px;? ? ? ? padding: 5px;? ? ? ? margin: 5px;? ? ? ? float: left;? ? ? ? border: 1px solid #ccc;? ? }? ? .left div {? ? ? ? background: #bbffaa;? ? }? ??? ? .right div {? ? ? ? background: yellow;? ? }? ? </style>? ? <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script></head><body>? ? <h2>.focusin()方法</h2>? ? <div class="left">? ? ? ? <div class="aaron">? ? ? ? ? ? 點(diǎn)擊聚焦:<input type="text" />? ? ? ? </div>? ? </div>? ? <div class="right">? ? ? ? <div class="aaron1">? ? ? ? ? ? 點(diǎn)擊聚焦并傳遞參數(shù):<input type="text" />? ? ? ? </div>? ? </div>? ? <script type="text/javascript">? ? ? ? //input聚焦? ? ? ? //給input元素增加一個(gè)邊框? ? ? ? $("input:first").focusin(function() {? ? ? ? ? ? ?$(this).css('border','2px solid red')? ? ? ? })? ? </script>? ? <script type="text/javascript">? ? ? ? //不同函數(shù)傳遞數(shù)據(jù)? ? ? ? function fn(e) {? ? ? ? ? ? ?$(this).val(e.data)? ? ? ? }? ? ? ? function a() {? ? ? ? ? ? $("input:last").click('慕課網(wǎng)', fn)? ? ? ? }? ? ? ? a();? ? </script></body></html>代碼里面不管是focusin改成click事件還是反過(guò)來(lái),都是一樣的效果,那兩個(gè)事件有什么區(qū)別嗎?
2 回答
已采納

qq_包包世界我專(zhuān)業(yè)_0
TA貢獻(xiàn)14條經(jīng)驗(yàn) 獲得超1個(gè)贊
區(qū)別很大,focusin事件只能用于能獲得焦點(diǎn)的元素,比如用在DIV元素里就沒(méi)效果了, click可用于任何元素

下雨何
TA貢獻(xiàn)28條經(jīng)驗(yàn) 獲得超23個(gè)贊
謝邀,jquery不是特別的熟悉
但是jquery作為一個(gè)js這么流行的框架,它肯定不會(huì)做傻事
所以我從函數(shù)名試圖來(lái)猜測(cè)兩個(gè)函數(shù)的不同,一個(gè)是焦點(diǎn),一個(gè)是點(diǎn)擊
很顯然,幾乎所有html元素都可以有點(diǎn)擊事件,但不是所有的html元素都可以有焦點(diǎn)事件
所以,應(yīng)該是個(gè)應(yīng)用范圍的不同,在某些場(chǎng)景focusin比click更適合
另外,百度了一下,focusin更應(yīng)該跟focus進(jìn)行對(duì)比
focus指當(dāng)前元素,focusin可以相應(yīng)當(dāng)前元素及其子元素
添加回答
舉報(bào)
0/150
提交
取消