$(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://idcbgp.cn/static/lib/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ù)
? ? ? ? ? ? $("input:last").focusin('慕課網(wǎng)', function fn(e) {
? ? ? ? ? ? ?$(this).val(e.data)
? ? ? ? ? ? });
? ? </script>
</body>
</html>
2018-03-21
$("input:last").focusin('慕課網(wǎng)', function fn(e) {
? ? ? ? ? ? ?$(this).val(e.data)
? ? ? ? ? ? });
首先,因?yàn)?("ele").focusin('data','fn'),點(diǎn)擊文本框觸發(fā)焦點(diǎn)事件,'data'傳入了數(shù)據(jù):“慕課網(wǎng)”儲(chǔ)存在focusin件事里面(也就是這里的e),后面的e.data就是讀取你傳入的數(shù)據(jù):“慕課網(wǎng)”這3個(gè)中文。val()你應(yīng)該理解吧,就是把data數(shù)據(jù)輸入到input文本框里。也就是為什么你點(diǎn)擊文本框的時(shí)候會(huì)出現(xiàn)“慕課網(wǎng)”的原因了。
2018-03-21
e是focusin對(duì)象,我們?cè)谟胒ocusion函數(shù)的時(shí)候傳入了data的值是慕課網(wǎng),所以e.data就是慕課網(wǎng)