問題描述新人,學習刪除select列表中option的時候遇到了一個變量引用的問題,如下:1.用option[index] = null ,可以達到刪除目的;2.把option[index]賦值給某個變量,再把變量設置為null,無效,例:var a = option[index];
a = null;經思考后,已經明白了a實際是引用了option[index]的地址,后面設置a = null,只是改變了a的引用地址,option[index]實際沒有變化。但是,后面的問題我想不通了,代碼貼在下面。代碼<form action="" name="theForm">
<select name="theDay">
<option value="1">1</option>
</select></form><script>
var option = document.theForm.theDay.options[0]; document.theForm.theDay.options[0] = null; console.log(document.theForm.theDay.options[0]); //輸出 undefined
console.log(option); // 輸出 <option value="1">1</option></script>而我以為的輸出會是console.log(document.theForm.theDay.options[0]); //輸出 null console.log(option); // 輸出 null想了很久沒想明白,希望大神指點
- 1 回答
- 0 關注
- 458 瀏覽
添加回答
舉報
0/150
提交
取消