Where is the Documentation for all of the Javascript HTML Element Constructors?

后端 未结 4 1425
無奈伤痛
無奈伤痛 2020-12-19 16:58

I cannot seem to find it. Thanks!

Example:

$(\"#MySelect\").append(new Option(\"MyOption\", \"MyOption\", true, true));
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 17:42

    The Mozilla Dev Center is the de facto standard documentation site for all things JavaScript.

    option element reference:

    • HTML
    • HTMLOptionElement interface (which is implemented by the above)
    • W3C HTMLOptionElement interface spec

    Since you're using jQuery, however, there's a better way to construct elements.

    $('#MySelect').append('',
    {
        text: 'MyOption',
        value: 'MyOption',
        selected: true
    })
    

    I'm not sure what the last true argument should do - at least in Chrome, new Option('text', 'value', true, true) seems to return the same thing as new Option('text', 'value', true).

提交回复
热议问题