为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我把replaceAll换成replaceWith不行呢?求解

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>使用替换元素和内容</title>
        <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
        <link href="style.css" rel="stylesheet" type="text/css" />
    </head>
   
    <body>
        <h3>使用replaceAll()方法替换元素内容</h3>
        <span class="green" title="hi">我是屌丝</span>
       
        <script type="text/javascript">
            var $html = "<span class='red' title='hi'>我是土豪</span>";
            var $html5 = "<span class='blue' title='hello'>我是男神</span>";
            $(".green").replaceWith($html5);
        </script>
    </body>
</html>

正在回答

5 回答

因为 他的class “green” “red"  在css里边设置了   你的class”blue“ 没设置 背景是白的  字也是白的 所以看不到 但实际已经有了

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

<span class='blue' title='hello'>我是男神</span>

class='blue'  是什么意思?

你在css里加上 .blue{ background-color:blue; }就好了.

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

   你的$(".green").replaceWith($html5);代码写错了,当然不行,正确的是   $($html5).replaceWith(".green");

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

Hot_shit

你这个才是错的= =
2016-04-15 回复 有任何疑惑可以回复我~

你给“.blue”设置属性了么

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

$($html5).replaceAll(".green"); 注意被替换元素和替换元素  课程上有写

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

523827 提问者

我的意思是想把replace()方法替换成replaceWith()方法
2016-02-16 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
jQuery基础课程
  • 参与学习       154702    人
  • 解答问题       7289    个

加入课程学习,有效提高前端开发速度

进入课程

为什么我把replaceAll换成replaceWith不行呢?求解

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号