為什么刪除var p1 = document.getElementById("p1");仍然能實現p1的classname改變?
function?add(){
??????var?p1?=?document.getElementById("p1");
??????p1.className="one";
???}根據語法object.className=classname,為什么把上面的
var?p1?=?document.getElementById("p1");這段刪掉之后直接
function?add(){
??????p1.className="one";
???}p1的classname仍然會改變呢?這是編輯器的智能識別嗎?
2016-06-13
變量名剛好和ID名相同,樓上說的對
2016-06-13
因為那個p標簽的 id就是p1,? 你可以試一下,把<p>標簽里的id改成p3? 結果就不行了