html同一个页面引用不同版本jquery库

-----注意外部js文件一定保存格式为“utf_8 有格式”

<script> var jqa =$; </script>

<script> var jqa = jQuery.noConflict(true); </script>

var $ jqa=$.noConflict();

--------------如下 $不起作用、别名起作用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
<script> var jqa = jQuery.noConflict(true); </script>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script> var jqb = jQuery.noConflict(true); </script>
<title>无标题文档</title>
</head>

<body>
<input type="submit" name="butid" id="butid" value="提交" onclick="mes()" />
<script>
 function mes()
 {alert('我是a库'+jqa('#butid').val())
 
 alert('我是b库'+jqb('#butid').val())
 }
  
</script>

</body>
</html>

或者--------------如下 $、与别名都起作用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
<script> var jqa =  $; </script>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script> var jqb =  $; </script>
<title>无标题文档</title>
</head>

<body>
<input type="submit" name="butid" id="butid" value="提交" onclick="mes()" />
<script>
 function mes()
 {alert('我是a库'+jqa('#butid').val())
 
 alert('我是b库'+jqb('#butid').val())
 }
  
</script>

</body>
</html>

猜你喜欢

转载自blog.csdn.net/ozhy111/article/details/82532265