JQuery IE选择问题

JQuery IE Select Issue

本文关键字:问题 选择 IE JQuery      更新时间:2023-09-26

在使用IE7时遇到一些问题。IE8、Chrome、Firefox都运行良好,但IE7不会执行这些代码。

这是HTML选择(代码段)

<form name="frmCat" action="index3.html" method="get">
            <select id="mySelect" onChange="onchange1((this).options[this.selectedIndex].value);">
                <option>Select a Category</option>
            </select>

以下是在其他浏览器中运行良好的JavaScript(AJAX片段):

function onchange1(catname){
    //alert(catname);
            $.ajax({
            type: "GET",
            url: "xml/categories.xml",
            dataType: "xml",
            success: function(xml) {
                var div = $('#epcf-wrap');
                var findval = "Cat"
                $(xml).find('Cat').each(function(){
                    var cval = $(this).attr('name');
                                            if(catname === cval){
                                            // I bet there is an easier way to do this
                                            var xmlArr = [];
                                            var xml_EPCF_1_1        = $(this).find('EPCF_1_1').text();

我读到IE7和AJAX存在某种问题,我看到了一些迹象,表明应该进行某种形式的MSIE检查,但我是JavaScript和JQuery的新手,我所发现的一切都与我在这里所做的非常一致。

想法?

您不能使用内联javascript。使用jQuery方式。

$('#mySelect').change(function(){
    //You can get the select value by the way below.
    var catname = $(this).val();
    $.ajax({
        type: "GET",
        url: "xml/categories.xml",
        dataType: "xml",
        success: function(xml) {
            var div = $('#epcf-wrap');
            var findval = "Cat"
            $(xml).find('Cat').each(function(){
                var cval = $(this).attr('name');
                if(catname === cval){
                    //....
                }
            }
        }
    });
});

在IE7中使用ajax没有问题。

请在ajax调用中添加一个错误处理程序,并查看返回的错误消息。

还要确保您的方法获得正确的参数。

最后,

 $("#myselect").change(handler(event)) 

听起来有点干净。这在jquery文档中,位于:http://api.jquery.com/change