jqueryとprototypeを共存させる
4069 ワード
jqueryとprototypeを共存させるには、さまざまな方法があり、ニーズを見てあなたの方法を選択します.
プラグインがjqueryに依存しているため、jqueryを先にロードします.
ネット上には他の方法も流れていますが、自分で必要な順番にどの方法を使うかを選びましょう.
方法1:
方法2:
方式3:
プラグインがjqueryに依存しているため、jqueryを先にロードします.
<%= javascript_include_tag
"jquery"
,
"formValidator_min"
,
"formValidatorRegex"
%>
<script type=
"text/javascript"
>
var
$j
= jQuery.noConflict();
</script>
<%= javascript_include_tag
:defaults
%>
ネット上には他の方法も流れていますが、自分で必要な順番にどの方法を使うかを選びましょう.
方法1:
<html>
<head>
<script src=
"prototype.js"
></script>
<script src=
"jquery.js"
></script>
<script>
jQuery.noConflict();
// Use jQuery via jQuery(...)
jQuery(document).ready(function(){
jQuery(
"div"
).hide();
});
// Use Prototype with $(...), etc.
$(
'someid'
).style.display =
'none'
;
</script>
</head>
<body></body>
</html>
方法2:
<html>
<head>
<script src=
"prototype.js"
></script>
<script src=
"jquery.js"
></script>
<script>
var
$j
= jQuery.noConflict();
// Use jQuery via
$j
(...)
$j
(document).ready(function(){
$j
(
"div"
).hide();
});
// Use Prototype with $(...), etc.
$(
'someid'
).style.display =
'none'
;
</script>
</head>
<body></body>
</html>
方式3:
<html>
<head>
<script src=
"prototype.js"
></script>
<script src=
"jquery.js"
></script>
<script>
jQuery.noConflict();
// Put all your code
in
your document ready area
jQuery(document).ready(function($){
// Do jQuery stuff using $
$(
"div"
).hide();
});
// Use Prototype with $(...), etc.
$(
'someid'
).style.display =
'none'
;
</script>
</head>
<body></body>
</html>