</select& gt;的JQuery .append标签被忽略 [英] JQuery .append of a </select> tag ignored

查看:87
本文介绍了</select& gt;的JQuery .append标签被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML:

<div id='show-label'>
  <select id="comboboxShowLabel">
    <option value="">Hide or show labels?</option>
    <option value="Show Labels">Show Label</option> 
    <option value="Hide Labels">Hide Label</option>
  </select>
</div>

我想在运行时将<select></select>添加到父div ala:

I want to add the the <select></select> to the parent div at runtime, ala:

     <div id='show-label'>
     </div>

    $("#show-label").html("<select id='comboboxShowLabel'>")
        .append("<option value=''>Hide or show labels?</option>")
        .append("<option value='Show Labels'>Show Label</option>")
        .append("<option value='Hide Labels'>Hide Label</option>")
        .append("</select>");       

对于我不知道的共鸣,没有将结束标签插入页面.

For resons unknown to me, the closing tag isn't getting injected into the page.

我已经尝试了上面的代码以及类似的代码:

I've tried the code above as well as something like this:

.append("<option value='Hide Labels'>Hide Label</option></select>")

在将这些元素分批"成单个.append时是否存在某种排序要求?我想知道这种方法在加载到DOM时是否看起来格式不正确,因此被忽略了……

Is there some sort requirement around "batching" these elements into a single .append? I'm wondering if this approach doesn't seem well-formed when it's loading into the DOM, so it's ignored...

谢谢!

推荐答案

尝试一下:

$("#show-label").append(function() {
    return $("<select id='comboboxShowLabel'>")
        .append("<option value=''>Hide or show labels?</option>")
        .append("<option value='Show Labels'>Show Label</option>")
        .append("<option value='Hide Labels'>Hide Label</option>");
});

这篇关于&lt;/select&amp; gt;的JQuery .append标签被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆