最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - $('body').layout is not a function - Stack Overflow

programmeradmin1浏览0评论

I'm using the jQuery UI Layout plugin and I keep getting this error in Firebug: $('body').layout is not a function. I also get the same error in IE8 and below.

Obviously, it's being caused by the line where I initiate the layout UI in my scripts file:

$('body').layout({ *options here* });

Is there a way to prevent this error from showing? I'm pretty sure I need the BODY selector for this particular plugin to run.

** SOLUTION **

As the helpful answers say below, I had this line: $('body').layout({ *options here* }); BEFORE I included my jQuery and jQuery UI Layout Plugin files. Once I put the body.layout after those two inclusions, the error went away.

I'm using the jQuery UI Layout plugin and I keep getting this error in Firebug: $('body').layout is not a function. I also get the same error in IE8 and below.

Obviously, it's being caused by the line where I initiate the layout UI in my scripts file:

$('body').layout({ *options here* });

Is there a way to prevent this error from showing? I'm pretty sure I need the BODY selector for this particular plugin to run.

** SOLUTION **

As the helpful answers say below, I had this line: $('body').layout({ *options here* }); BEFORE I included my jQuery and jQuery UI Layout Plugin files. Once I put the body.layout after those two inclusions, the error went away.

Share Improve this question edited Aug 9, 2012 at 18:26 Daniel Li 15.4k6 gold badges44 silver badges60 bronze badges asked Aug 7, 2012 at 15:12 FastTrackFastTrack 8,99014 gold badges59 silver badges78 bronze badges 1
  • 1 Make sure you are including the jQuery layout plugin script into your page and that you are only including one copy of jquery. – Kevin B Commented Aug 7, 2012 at 15:16
Add a ment  | 

2 Answers 2

Reset to default 4

You seem to either

1) have not included the plugin properly (script tag missing/typo in the url, included it before loading jquery itself, whatever else could go wrong)

 or

2) calling $("body").layout too early - wrap it with $(document).ready(function() { });

it should be

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.layout.js"></script>

...

<script type="text/javascript">
   $(document).ready(function() {
      $("body").layout() // will work now
   });
</script>

Make sure you're including the lines:

<SCRIPT type="text/javascript" src="/path/to/jquery-latest.js"></SCRIPT>
<SCRIPT type="text/javascript" src="/path/to/jquery.layout-latest.js"></SCRIPT>

Prior to the code you placed in your question. Otherwise, layout will have been undefined before use.

发布评论

评论列表(0)

  1. 暂无评论