なぜこれが機能しないのかわかりませんか?そして、小さなオプションを削除しないでください!
私はスクリプトを持っています:
<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>