jQuery html属性在IE中不起作用 [英] jQuery html attribute not working in IE

查看:150
本文介绍了jQuery html属性在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是国家和州的下拉菜单。每当用户在下拉菜单中选择国家时,该国家的相应州将填入州下拉菜单中。我使用AJAX调用在下拉列表中填充状态。问题在于状态在Mozilla中填充,但在IE中不起作用。我想在jQuery的状态下拉列表中加载状态时会出现一些问题。我使用的jQuery代码是

  $('select#edit-country')。change(function(e){

$ .getJSON(loadContactUsStates,{id:$(this).val(),ajax:'true'},function(j){
var options ='';

for(var i = 0; i options + ='< option value =''+ j [i] .optionValue +'> ;'+ j [i] .optionDisplay +'< / option>';

}

<!-----我想问题是下面一行------------------>
$(select#edit-state)。html(options);

})//结束json

});


解决方案

尝试使用追加 html 方法的详细信息,详见 post

编辑

其实,我我自己就会遇到这个问题。对我来说,答案是首先调用,然后 append ,它与使用html方法具有相同的效果(我认为?)。


I am using country and state dropdowns in my form. Whenever the user selects the country in the dropdown, the respective states of the country will populate in the states dropdown. I am populating the states in the dropdown using AJAX call. The problem is that the states get populated in Mozilla but it doesn't work in IE. I guess there is some problem in jQuery while loading the states in the states dropdown. The jQuery code i am using is

$('select#edit-country').change(function(e) {

    $.getJSON("loadContactUsStates",{id: $(this).val(), ajax: 'true'}, function(j){
        var options = '';

        for (var i = 0; i < j.length; i++) { 
            options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';

        }

    <!-----I guess the problem is with the below line------------------>
       $("select#edit-state").html(options);

    })//end json

});

解决方案

Try using append instead of the html method as detailed in this post.

edit

Actually, I've just run into this problem myself. For me the answer was to call empty first, then append which has the same effect (I think?) as using the html method.

这篇关于jQuery html属性在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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