亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

如何多次實現點擊聚焦并傳遞參數?

<!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">

? ? ? ? ? ? 點擊聚焦:<input type="text" />

? ? ? ? ? ? <br>

? ? ? ? ? ? 點擊聚焦:<input type="text" />

? ? ? ? </div>


? ? </div>

? ? <div class="right">

? ? ? ? <div class="aaron1">

? ? ? ? ? ? 點擊聚焦并傳遞參數:<input type="text" />

? ? ? ? ? ? <br>

? ? ? ? ? ? 點擊聚焦并傳遞參數:<input type="text" />

? ? ? ? </div>

? ? ? ??

? ? </div>



? ? <script type="text/javascript">


? ? ? ? //input聚焦

? ? ? ? //給input元素增加一個邊框

? ? ? ? $("input:last-child").focusin(function() {

? ? ? ? ? ? ?$(this).css('border','12px solid red')

? ? ? ? })

? ? ? ??

? ? ? ? //D

? ? ? ? $("input:first").focusin(function(){

? ? ? ? ? ? $(this).css('border',"12px solid green")

? ? ? ? })

? ? </script>



? ? <script type="text/javascript">


? ? ? ? //不同函數傳遞數據

? ? ? ? function fn(e) {

? ? ? ? ? ? ?$(this).val(e.data)

? ? ? ? }


? ? ? ? function a() {

? ? ? ? ? ? $('input:first-child.focusin('慕課網', fn)

? ? ? ? }

? ? ? ? a();

? ??

? ? ? ? //DIY

? ? ? ? function fn(e){

? ? ? ? ? ? $(this).val(e.data)

? ? ? ? }

? ? ? ??

? ? ? ? function a(){

? ? ? ? ? ? $("input:last-child").focusin("請輸入密碼",fn)

? ? ? ? }

? ? ? ? a();

? ? </script>

</body>


</html>


黑體是我自己增加的,為什么這時候第一個框就無法實現點擊聚焦并傳遞參數了?


正在回答

2 回答

<!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">

? ? ? ? ? ? 點擊聚焦:<input type="text" />

? ? ? ? ? ? <br>

? ? ? ? ? ? 點擊聚焦:<input type="text" />

? ? ? ? </div>


? ? </div>

? ? <div class="right">

? ? ? ? <div class="aaron1">

? ? ? ? ? ? 點擊聚焦并傳遞參數:<input type="text" />

? ? ? ? ? ? <br>

? ? ? ? ? ? 點擊聚焦并傳遞參數:<input type="text" />

? ? ? ? </div>

? ? ? ??

? ? </div>



? ? <script type="text/javascript">


? ? ? ? //input聚焦

? ? ? ? //給input元素增加一個邊框

? ? ? ? $("input:eq(1)").focusin(function() {

? ? ? ? ? ? ?$(this).css('border','1px solid red')

? ? ? ? })

? ? ? ??

? ? ? ? //D

? ? ? ? $("input:eq(0)").focusin(function(){

? ? ? ? ? ? $(this).css('border',"1px solid green")

? ? ? ? })

? ? </script>



? ? <script type="text/javascript">


? ? ? ? //不同函數傳遞數據

? ? ? ? function fn(e) {

? ? ? ? ? ? ?$(this).val(e.data)

? ? ? ? }


? ? ? ? function b() {

? ? ? ? ? ? $("input:eq(2)").focusin("慕課網", fn)

? ? ? ? }

? ? ? ? b();

? ??

? ? ? ? //DIY

? ? ? ? function fn(e){

? ? ? ? ? ? $(this).val(e.data)

? ? ? ? }

? ? ? ??

? ? ? ? function a(){

? ? ? ? ? ? $("input:eq(3)").focusin("請輸入密碼",fn)

? ? ? ? }

? ? ? ? a();

? ? </script>

</body>


</html>


0 回復 有任何疑惑可以回復我~
#1

12只怕有心人 提問者

非常感謝!
2016-10-13 回復 有任何疑惑可以回復我~

自己對比了下兩段代碼發現如下

1.首先選擇器last和last child,first和first child是不一樣的

????四個input分別為eq(0)-(3)

????在點擊聚焦和點擊聚焦并傳遞參數的2段代碼中,

????如果用

?????$("input:last")作為選擇器,結果只改變了eq(3)

?????$("input:last-child")作為選擇器,改變eq(1)和eq(3)

?????$("input:first")作為選擇器,結果只改變了eq(0)

?????$("input:first-child")作為選擇器,改變eq(0)和eq(2)

?????多個“child"就需要滿足兩個條件:

???? 被選取input有父元素,而且input是該父元素的第一個元素

2.//不同函數傳遞數據中兩個函數起名不能重復.

3. ?$('input:first-child.focusin('慕課網', fn) 中漏了一個)?

還要再打牢基礎.









1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

如何多次實現點擊聚焦并傳遞參數?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號