<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/jquery-3.6.0.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-migrate-1.4.1.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-migrate-3.3.2.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h1>asdfsdf</h1>
<h1>asdfga</h1>
<h1>asdfsdf</h1>
<h1>asdfga</h1>
<script type="text/javascript">
$('h1').click(function(){
// this.innerHTML = $(this).attr('num');
//为什么换成这个就会报左侧无效赋值
$(this).html() = $(this).attr('num');
})
</script>
</body>
</html>
这是一个语法错误。因为 $(this).html()
返回一个字符串,不能将值赋给一个常量字符串。比如:
"abc" = 123 // Uncaught SyntaxError: Invalid left-hand side in assignment