<选项>不附加在< select>在jquery [英] <option> not append in <select> in jquery

查看:69
本文介绍了<选项>不附加在< select>在jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过解析来自XMl的数据,使用javascript在< select> 中附加< option> 。正确地从xml解析数据,但它没有附加在< select> 中。

I have tried to append <option> inside <select> using javascript by parsing data from XMl. Data parsed from xml properly,but it is not appending in <select>.

此外,我想将选项显示为(图像+文本)格式。怎么做....

Also I want to show option as (image+text) format. How to do this....

我的HTML代码:

<form style="margin:20px 0">
    <p>
        <select id='mySelect' multiple="multiple" style="width:370px">
        </select>
    </p>

</form>

Javascript代码:

$(document).ready(function(){

    $.ajax({
        type: "GET",
        url: "newpersonal1.xml",
        dataType: "xml",
        success: function(xml) {
            var select = $('#mySelect');
            $(xml).find('value').each(function(){
                 var title = $(this).find('name').text();
                 alert(title);
                 select.append("<option value='"+title+"'>"+title+"</option>");         
            });                 
        }
    });
});

如何修复此问题并在选择<选项> <中添加图片/ code>。

How to fix this issue and add image in select <option>.

推荐答案

当你处理过滤和多选插件时,你必须采取额外的步骤方式。

You have to make additional steps when you deal with "filter and multiselect plugin" in your way.

它模仿选择对象,隐藏原始对象并创建一组按钮和跨度元素。它仅在初始化时使用原始的。

It mimics the select object, hiding the original one and creating the set of button and span elements. It uses the original one only at the moment of initialization.

因此,只要使用其他选项更新原始选择标记,就必须调用函数refresh()。

So, you have to call function refresh() as soon as you update the original select tag with additional options.

http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/#refresh

这篇关于&LT;选项&GT;不附加在&lt; select&gt;在jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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