我正在学习jQuery并尝试更改跨度的文本。我有这个:
<!DOCTYPE html>
<html>
<head>
<title>jQuery</title>
<meta charset="utf-8"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<span id="address"></span>
</div>
</div>
</div>
<script type="text/javascript">
$("#address").html("Hello World!");
</script>
</body>
</html>
&#13;
但是,它不起作用。我在jsFiddle上试过它并且它有效,所以我不确定是什么错。我应该加入别的吗?
答案 0 :(得分:-1)
您需要在加载时执行代码:
<script type="text/javascript">
$(function() {
$("#address").html("Hello World!");
});
</script>