简体   繁体   English

为什么下面的jquery不运行?

[英]Why doesn't the following piece of jquery run?

I'm trying to fetch some html with jquery/ajax, load it into a div, then call the show method with the blind effect on it. 我正在尝试使用jquery / ajax获取一些html,将其加载到div中,然后调用对它具有盲目的效果的show方法。 But I can't figure out what's going wrong for the life of me. 但是我无法弄清楚我一生中出了什么问题。

 $(document).ready(function() { // The relevant jQuery
    $("#effect").hide(); // Make sure the div I'm going to show is not visible first off.
    $("#foo").click(function(){  // foo is a button
        $.ajax({url:"after.html", success:function(result){ // Grab the html I want.  (just an <h1> tag)
            $("#effect").html(result).show("blind", {direction: "horizontal"}, 400); // When I comment out this line it works, but with the exception of the id's to select it's exactly the same as in another working page.
            alert("loaded after.html...");
        }});
    });
});

HTML: HTML:

<div class="narrow">
   <p><input type="submit" id="foo"/></p>
</div>


<div id="effect" style="background-color:white; float:right; height:400px; width:400px;">
</div>

Without calling the $("#effect").html(result).show("blind", {direction: "horizontal"}, 400); 而不调用$("#effect").html(result).show("blind", {direction: "horizontal"}, 400); line, everything runs fine. 行,一切运行正常。 However, with that line it says Uncaught SyntaxError: Unexpected end of input in the console. 但是,在该行中显示Uncaught SyntaxError: Unexpected end of input控制台Uncaught SyntaxError: Unexpected end of input (Chrome) (铬)

I was using this page as a reference when I ran into this problem. 遇到此问题时,我已将此页面用作参考。

What's going on here? 这里发生了什么?

Blind effect is a part of JQueryUI. 盲效果是JQueryUI的一部分。 In the tutorial you shared, you can see that code. 在您共享的教程中,您可以看到该代码。 Are you sure that something like jquery-ui-1.7.2.custom.min.js is referenced on your page as: 您确定在页面jquery-ui-1.7.2.custom.min.js诸如jquery-ui-1.7.2.custom.min.js内容引用为:

<script type="text/javascript" src="/jquery/jquery-ui-1.7.2.custom.min.js"></script>

I let this problem sit for a while, then I came back to work and took out the alert("loaded after.html..."); 我让这个问题坐了一会儿,然后我恢复工作并发出alert("loaded after.html..."); It then worked fine. 然后工作正常。 I have no idea what caused this, but I can only assume that the alert disrupted it somehow. 我不知道是什么原因造成的,但是我只能假设警报以某种方式破坏了它。

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

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