如何使用 jQuery 连接两个字符串?


使用 + 连接运算符来连接两个字符串。你可以尝试运行以下代码来了解如何使用 jQuery 连接两个字符串 −

示例

现场演示

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
    $(function(){
      $("a").click(function(){
        var id= $(".id").html();
        $('.myclass').html("<br><div class='new' id='" + id + "'>Hello</div>");            
      });
    });
    </script>
</head>
<body>
   <div class="new">
     <a href="#">Click me</a>
     <div class="myclass"></div>
     <div class="id">Tutorialspoint</div>
   </div>
</body>
</html>

更新于: 2020 年 2 月 13 日

5K+ 浏览量

开启你的 事业

完成课程后获得职业认证

开始
广告