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

jqueryweb developmentfront end technology更新于 2026/1/16 4:52:17

要连接两个字符串,请使用 + 连接运算符。您可以尝试运行以下代码来学习如何使用 jQuery − 连接两个字符串。

示例

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/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>

相关文章