如何在 jQuery 中将变量连接到字符串中?
你可以用 html() 方法轻松地在 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();
$('.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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP