ๆญค้กต้ข็”ฑ็คพๅŒบไปŽ่‹ฑๆ–‡็ฟป่ฏ‘่€Œๆฅใ€‚ไบ†่งฃๆ›ดๅคšๅนถๅŠ ๅ…ฅ MDN Web Docs ็คพๅŒบใ€‚

View in English Always switch to English

HTMLSelectElement.remove()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Itโ€™s been available across browsers since โจ2015ๅนด7ๆœˆโฉ.

HTMLSelectElement.remove() ๆ–นๆณ•ไปŽไธ€ไธช select ๅ…ƒ็ด ไธญๅˆ ้™คๆŒ‡ๅฎšๅบๆ•ฐ็š„ option ๅ…ƒ็ด ใ€‚ๆฒกๆœ‰ไผ ๅ‚ๆ—ถไธบๅˆ ้™คๅฝ“ๅ‰ๅ…ƒ็ด ๆœฌ่บซ๏ผšChildNode.remove()ใ€‚

่ฏญๆณ•

js
remove(index)

ๅ‚ๆ•ฐ

  • index ๆ˜ฏไปŽ option HTMLOptionElement ้›†ๅˆไธญ่ฆ็งป้™คๅ…ƒ็ด ็š„ๅบๆ•ฐใ€‚ๅฆ‚ๆžœๅบๆ•ฐๅฏนๅบ”็š„ๅ…ƒ็ด ไธๅญ˜ๅœจ๏ผŒ่ฐƒ็”จ่ฟ™ไธชๆ–นๆณ•ๅฐฑๆฒกๆœ‰ไปปไฝ•ๆ•ˆๆžœใ€‚

ไพ‹ๅญ

js
var sel = document.getElementById("existingList");
sel.remove(1);

/*
  ไธŠ้ข็š„ไปฃ็ ไผšๅฐ†ไธ‹้ข็š„ select ๅ…ƒ็ด ็ป“ๆž„๏ผš

  <select id="existingList" name="existingList">
    <option value="1">Option: Value 1</option>
    <option value="2">Option: Value 2</option>
    <option value="3">Option: Value 3</option>
  </select>

  ๅ˜ๆˆ่ฟ™ๆ ท๏ผš

  <select id="existingList" name="existingList">
    <option value="1">Option: Value 1</option>
    <option value="3">Option: Value 3</option>
  </select>
*/

Specifications

Specification
HTML
# dom-select-remove

ๆต่งˆๅ™จๅ…ผๅฎนๆ€ง

ๅ‚่€ƒ