$(this).val(e.data)中的data如何解釋???
<!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://www.xianlaiwan.cn/static/lib/jquery/1.9.1/jquery.js"></script>
</head>
<body>
? ? <h2>.focusin()方法</h2>
? ? <div class="left">
? ? ? ? <div class="aaron">
? ? ? ? ? ? 點擊聚焦:<input type="text" />
? ? ? ? </div>
? ? </div>
? ? <div class="right">
? ? ? ? <div class="aaron1">
? ? ? ? ? ? 點擊聚焦并傳遞參數:<input type="text" />
? ? ? ? </div>
? ? </div>
? ? <script type="text/javascript">
? ? ? ? //input聚焦
? ? ? ? //給input元素增加一個邊框
? ? ? ? $("input:first").focusin(function() {
? ? ? ? ? ? ?$(this).css('border','2px solid red')
? ? ? ? })
? ? </script>
? ? <script type="text/javascript">
? ? ? ? //不同函數傳遞數據
? ? ? ? ? ? $("input:last").focusin('慕課網', function fn(e) {
? ? ? ? ? ? ?$(this).val(e.data)
? ? ? ? ? ? });
? ? </script>
</body>
</html>
2018-03-21
$("input:last").focusin('慕課網', function fn(e) {
? ? ? ? ? ? ?$(this).val(e.data)
? ? ? ? ? ? });
首先,因為$("ele").focusin('data','fn'),點擊文本框觸發焦點事件,'data'傳入了數據:“慕課網”儲存在focusin件事里面(也就是這里的e),后面的e.data就是讀取你傳入的數據:“慕課網”這3個中文。val()你應該理解吧,就是把data數據輸入到input文本框里。也就是為什么你點擊文本框的時候會出現“慕課網”的原因了。
2018-03-21
e是focusin對象,我們在用focusion函數的時候傳入了data的值是慕課網,所以e.data就是慕課網