換成<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>P2才能顯示這是為什么呢,原先是 <script src="http://code.jquery.com/jquery-1.11.3.js"></script>
<head>
? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
? ? <title></title>
? ? <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
? ??
? ? <!-- 使用JS原生語法 -->
? ? <script type="text/javascript">
? ? ? ? window.onload = function(){
? ? ? ? ? ? // 通過原生JS語法獲取id為imooc1的元素p
var p = document.getElementById('imooc1');
? ? ? ? ? ? // 將元素p在html中內(nèi)容改變
p.innerHTML = 'P1:您好!通過慕課網(wǎng)學習jQuery才是最佳的途徑';
? ? ? ? ? ? // 將元素p的內(nèi)容顏色改為紅色
p.style.color = 'red';
? ? }
? ? </script>
? ??
? ? <!-- 使用jQuery語法 -->
? ? <script type="text/javascript">
? ? ? ? $(document).ready(function() {
? ? ? ? ? ? /**
? ? ? ? ? ? ?* 通過jQuery語法獲取id為imooc2的元素獲得一個jQuery對象
? ? ? ? ? ? ?* 調(diào)用該對象的html()方法進行更改內(nèi)容
? ? ? ? ? ? ?* 調(diào)用該對象的css()方法進行更改顏色樣式
? ? ? ? ? ? ?*/ ??
? ? ? ? ? ? ? ?var $p = $('#imooc2');
? ? ? ? ? ? $p.html('P2:您好!通過慕課網(wǎng)學習jQuery才是最佳的途徑').css('color','red');
? ? ? ? });
? ? </script>
? ??
</head>
<body>
? ? <p id="imooc1"></p>
? ? <p id="imooc2"></p>
2016-12-14
可能是慕課網(wǎng)的服務(wù)器訪問不了這個js地址吧:http://code.jquery.com/jquery-1.11.3.js
2017-01-19
非常感謝
2017-01-08
最好辦法就是下載jquery-3.0.0.js解壓后放入與html并列文件夾中,html修正為<script type="text/javascript" src="jquery-3.0.0.js"></script>,并將練習代碼復入運行,試一試吧