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

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

问题描述

我有以下HTML:

 < div id ='show-label'> 
< select id =comboboxShowLabel>
< option value =>隐藏或显示标签?< / option>
< option value =显示标签>显示标签< / option>
< option value =隐藏标签>隐藏标签< / option>
< / select>
< / div>

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

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

$(#show-label)。html(< select id ='comboboxShowLabel'>)
.append(< option value =''>隐藏或显示标签?< / option>)
.append(< option value ='Show Labels'> Show Label< / option>)
.append(< option value ='Hide Labels'>隐藏标签< / option>)
.append(< / select>);

对于我未知的资源,结束标签没有注入页面。 >

我已经尝试了上面的代码以及这样的东西:

  .append(< option value ='Hide Labels'>隐藏标签< / option>< / select>)

有没有一些排序要求,将这些元素批处理为单个.append?我想知道如果这种方法在加载到DOM中似乎没有形成,所以它被忽略...



谢谢!

解决方案

尝试这样:

  $(#显示标签)append(function(){
return $(< select id ='comboboxShowLabel'>)
.append(< option value =''>或显示标签?< / option>)
.append(< option value ='显示标签'>显示标签< / option>)
.append(< ='隐藏标签'>隐藏标签< / option>);
});


I have the following 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>

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>")

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...

Thanks!

解决方案

Try this:

$("#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&gt;的JQuery .append标签被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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