如何防止关闭 </option> 标签被删除?

How to prevent a closing </option> tag from being removed?

我想达到这样的效果

<select id="funsports" name="funsports">
   <option value="">sports</option>
   <option value="football">football</option>
   <option value="tennis">tennis</option>
</select>

但是当我保存小部件时,它会强行删除末尾的结束标记。当我在博客小部件中使用这种类型的选项时,我遇到了这样的问题。

如何在最后用</option>标签强行关闭?使用 jQuery 或 JavaScript 的任何方式,或者我们只能通过 HTML 和 CSS 来实现。

<select id="fungames" name="fungames">
  <option value="" />games
  <option value="roadrash" />roadrash
  <option value="gta" />gta
</select>

W3.org 说:

Tag omission

An option element must have a start tag. An option element’s end tag may be omitted if the option element is immediately followed by another option element, or if it is immediately followed by an optgroup element, or if there is no more content in the parent element.

正如其他人所说,这不是实际问题,但如果您真的想要最后一个标签,只需使用 jQuery:https://jsfiddle.net/tu3wpzsj/3/

$(document).ready(function() {
    $('select').append('</option>');
    $('option').each(function(i){
        if(i!=0) $(this).before('</option>');
    });
});