代码之家  ›  专栏  ›  技术社区  ›  cnemelka

JQuery在除IE 6.0/7.0以外的所有浏览器中都存在问题:)

  •  0
  • cnemelka  · 技术社区  · 17 年前

    没想到我会有这个问题:)

    以下代码片段适用于IE 6.0/7.0,但不适用于其他浏览器(“兼容性视图”中的IE 8.0):

    $(document).ready(function(){
    
        // Search button code
        $('#btnSearch').click(function() { //start function when button is clicked
                var sid = $('#search_id').val();
                $.ajax({
                        method: "get",url: "controller.php",data: { search_id:sid, action:'search'} ,
                        beforeSend: function(){$("#loading").show("slow");}, //show loading just when link is clicked
                        complete: function(){ $("#loading").hide("slow");}, //stop showing loading when the process is complete
                        success: function(html){ //so, if data is retrieved, store it in html
                                $('.main_content').html(html); //show the html inside .main_content div
                                $('.main_content').show("slow"); //animation
                        }
                });
    
                $("form").each(function() {
                        this.reset();
                });
        });
    });
    

    <div>
    <form id="srchForm" method="post" action="">
    <p><abbr title="Search ID"><label for="search_id">Search ID:</label></abbr><input   type="text" name="search_id" id="search_id">
    <button id="btnSearch" value="search">go</button>
    </p>
    </form>
    <div id="loading">LOADING!!!!!!!!!!!!!!!!<br></div>
    <hr>
    <div id="main_content" class="main_content"></div>
    </div>
    <div>
    <div class="add_content"></div>
    </div>
    

    谁能看出我做错了什么?

    2 回复  |  直到 17 年前
        1
  •  0
  •   SolutionYogi Eric Lippert    17 年前

    只是一个猜测,你能试着将你的按钮定义为“输入”标签而不是“按钮”标签吗?

    <input id="btnSearch" value="search" type="button" /> //Use this
    <button id="btnSearch" value="search">go</button> //instead of this
    

    试试看,看看有没有什么变化。

        2
  •  0
  •   BAH    17 年前

    快速查看,它看起来像:

    ajax方法的data属性允许JavaScript对象和字符串,但是除了JSON字符串之外,我从来没有使用过其他任何东西。在IE中,您可以使用JSON.Stringify(),但您应该看看一些JQuery插件。比如这个 jquery-json

    data: { search_id:sid, action:'search'} ,
    

    data: $.toJSON({ search_id:sid, action:'search'}) ,
    

    第二:

    $('.main_content').html(thml);
    

    否则代码在我看来很好。