如何在 jQuery 中连接字符串中的变量?

jqueryweb developmentfront end technology

您可以使用 jQuery 的 html() 方法轻松地在 jQuery 中连接字符串中的变量。尝试运行以下代码,了解如何在 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();
        $('.demo').html("<br><div class='new' id='" + id + "'>Welcome to </div>");            
      });
    });
    </script>
</head>
<body>
   <div class="wrap">
      <a href="#">Click me</a>
      <div class="demo"></div>
      <div class="id">Qries</div>
   </div>
</body>
</html>

相关文章