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

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

return '<div class="' + $(this).text() + '" />';?

<!DOCTYPE html>

<html>


<head>

? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

? ? <title></title>

? ? <script src="http://www.xianlaiwan.cn/static/lib/jquery/1.9.1/jquery.js"></script>

? ? <style>

? ? .left div,

? ? .right div {

? ? ? ? width: 100px;

? ? ? ? padding: 5px;

? ? ? ? margin: 5px;

? ? ? ? float: left;

? ? ? ? border: 1px solid #ccc;

? ? ? ? background: #bbffaa;

? ? }

? ??

? ? .right div {

? ? ? ? background: yellow;

? ? }

? ??

? ? p {

? ? ? ? border: 1px solid red;

? ? }

? ??

? ? a {

? ? ? ? border: 1px solid blue;

? ? }

? ? </style>

</head>


<body>

? ? <h2>DOM包裹wrap()方法</h2>

? ? <div class="left">

? ? ? ? <button class="aaron1">點擊,通過wrap方法給p元素增加父容器div</button>

? ? ? ? <button class="aaron2">點擊,通過wrap的回調方法給a元素增加父容器div</div>

? ? </div>

? ? <div class="right">

? ? ? ? <p>p元素</p>

? ? ? ? <p>p元素</p>

? ? </div>

? ? <div class="left">

? ? ? ? <a>a元素</a>

? ? ? ? <a>a元素</a>

? ? </div>

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

? ? $(".aaron1").on('click', function() {

? ? ? ? //給所有p元素,增加父容器div

? ? ? ? $('p').wrap('<div></div>')

? ? })

? ? </script>

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

? ? $(".aaron2").on('click', function() {

? ? ? ? $('a').wrap(function() {

? ? ? ? ? ? return '<div class="' + $(this).text() + '" />';????

? ? ? ? })

? ? })

? ? </script>

</body>


</html>


正在回答

3 回答

我第一次看也是相同的疑問,但功能卻實現了,我就猜測是不是

$('p').wrap('<div>');
$('p').wrap('<div></div>');
$('p').wrap('<div/>');

這三者是等價的,于是測試了一下,果然如此

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

這個class就沒有起作用

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

$(this).text()中的this指代元素a,即$("a").text(),意思是a元素,class="'a元素'",類選擇器的值‘a元素’,添加的并沒啥作用。

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

atlunix

thank you.
2018-09-17 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

return '<div class="' + $(this).text() + '" />';?

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

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

幫助反饋 APP下載

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

公眾號

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