简体   繁体   English

jQuery IE选择问题

[英]JQuery IE Select Issue

Having some trouble w/ IE7. 有一些麻烦瓦特/ IE7。 IE8, Chrome, Firefox all work fine, but IE7 won't execute this code. IE8,Chrome,Firefox都可以正常工作,但是IE7不会执行此代码。

Here's the HTML Select (Snippet) 这是HTML Select(代码段)

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

and here is the JavaScript that runs just fine in other browsers (AJAX snippet): 这是在其他浏览器中可以正常运行的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();

I've read that there is some sort of issue w/ IE7 and AJAX and I've seen some hints that there should be some form of MSIE check being done but I'm new to JavaScript and JQuery and nothing I've found aligns very clearly to what I'm doing here. 我读到有某种问题,带有IE7和AJAX,并且我已经看到一些暗示应该进行某种形式的MSIE检查,但是我是JavaScript和JQuery的新手,但我发现没有什么可以解决的很清楚我在这里做什么。

Thoughts? 有什么想法吗?

You could just not use the inline javascript. 您无法使用内联JavaScript。 Use the jQuery way. 使用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){
                    //....
                }
            }
        }
    });
});

there is no problem to use ajax in IE7. 在IE7中使用ajax没问题。

please add an error handler to the ajax call, and see what error message is returned. 请向ajax调用添加错误处理程序,然后查看返回了什么错误消息。

also make sure your method gets the proper parameter. 还要确保您的方法获取正确的参数。

last, 持续,

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

sounds a bit cleaner. 听起来有点干净。 this is in the jquery doc at: http://api.jquery.com/change 这是在jQuery文档中: http : //api.jquery.com/change

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM