ITeye博客

jquery-ui创建tab页时报Object [object Object] has no method 'tabs'错误

ldz0414 · 2013-12-12 10:53 · jquery · html · Web前端 · Markdown

如题今天遇到了一个创建tab页时报jQuery is not defined。接着报Object has no method 'tabs'的错误。 代码如下:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>tab.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <link type="text/css" rel="stylesheet" href="jquery-ui-1.7.2.custom.css"/>
    <script type="text/javascript" src="jquery-ui-1.7.2.custom.min.js"></script>
    <script type="text/javascript" src="jquery-1.7.1.js"></script>
	<script>
		jQuery(function() {
   			jQuery("#tabs").tabs({
    			event: 'click'
   			});
		});
	</script>
  </head>
  
  <body>
    <div id="tabs">
	   <ul>
	      <li><a href="#tabs-1">one</a></li>
	      <li><a href="#tabs-2">two</a></li>
	      <li><a href="#tabs-3">three</a></li>
	   </ul>
	   <div id="tabs-1">
	      <p>Tab 1 content</p>
	   </div>
	   <div id="tabs-2">
	      <p>Tab 2 content</p>
	   </div>
	   <div id="tabs-3">
	      <p>Tab 3 content</p>
	   </div>
	</div>
  </body>
</html>

由于JS是解释型语言,是根据标签引用分块顺序执行的,$是jQuery中的产生的对象,需要用的话,必须将jquery.js文件放在使用它的JS前面。故调整jquery-1.7.1.js和jquery-ui-1.7.2.custom.min.js的顺序,将jquery-1.7.1.js放在前面。问题解决


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>tab.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <link type="text/css" rel="stylesheet" href="jquery-ui-1.7.2.custom.css"/>
    <script type="text/javascript" src="jquery-1.7.1.js"></script>
    <script type="text/javascript" src="jquery-ui-1.7.2.custom.min.js"></script>
	<script>
		jQuery(function() {
   			jQuery("#tabs").tabs({
    			event: 'click'
   			});
		});
	</script>
  </head>
  
  <body>
    <div id="tabs">
	   <ul>
	      <li><a href="#tabs-1">one</a></li>
	      <li><a href="#tabs-2">two</a></li>
	      <li><a href="#tabs-3">three</a></li>
	   </ul>
	   <div id="tabs-1">
	      <p>Tab 1 content</p>
	   </div>
	   <div id="tabs-2">
	      <p>Tab 2 content</p>
	   </div>
	   <div id="tabs-3">
	      <p>Tab 3 content</p>
	   </div>
	</div>
  </body>
</html>

经验不足

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。