我不明白为什么这不起作用?而不是删除小选项!
我有脚本:
<script>
var quantity_in_stock_s = 0
if ( quantity_in_stock_s === 0)
{
var S = document.getElementById("S");
document.getElementById("mySelect").removeChild(S);
}
</script>
和 HTML:
<form>
<select id="mySelect">
<option id="S">Small</option>
<option id="M">Medium</option>
<option id="L">Large</option>
</select>
</form>
这有错吗?!!:
</head>
<body>
<form>
<select id="mySelect">
<option id="S">Small</option>
<option id="M">Medium</option>
<option id="L">Large</option>
</select>
</form>
<script>
var quantity_in_stock_S = 0
var quantity_in_stock_M = 0
var quantity_in_stock_L = 0
function deleteOption1(){
if ( quantity_in_stock_S === 0)
{
var S = document.getElementById("S");
document.getElementById("mySelect").removeChild(S);
}
}
function deleteOption2(){
if ( quantity_in_stock_M === 0)
{
var M = document.getElementById("M");
document.getElementById("mySelect").removeChild(M);
}
}
function deleteOption3(){
if ( quantity_in_stock_L === 0)
{
var L = document.getElementById("L");
document.getElementById("mySelect").removeChild(L);
}
}
window.onload = deleteOption1;
window.onload = deleteOption2;
window.onload = deleteOption3;
</script>