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

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

问题描述

我在表单中使用国家和州下拉列表.每当用户在下拉列表中选择国家/地区时,该国家/地区的相应州将填充到州下拉列表中.我正在使用 AJAX 调用填充下拉列表中的状态.问题是状态在 Mozilla 中填充,但在 IE 中不起作用.我猜在状态下拉列表中加载状态时 jQuery 中存在一些问题.我使用的 jQuery 代码是

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

});

推荐答案

尝试使用 append 代替 html 方法,如本post.

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

编辑

实际上,我自己刚刚遇到了这个问题.对我来说,答案是先调用 empty,然后是 append 与使用 html 方法具有相同的效果(我认为?).

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天全站免登陆