问题jQuery和Prototype [英] Problem jQuery and Prototype
问题描述
朋友我的jquery和原型有问题:
< head>
< link rel =stylesheettype =text / csshref =http://localhost/ecommerce/css/lightview.css/>
< script type =text / javascriptsrc =http://localhost/ecommerce/js/jquery-1.3.2.min.js>< / script>
< script type ='text / javascript'src ='http://ajax.googleapis.com/ajax/libs/prototype/1.6.1/prototype.js'>< / script>
< script type ='text / javascript'src ='http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.2/scriptaculous.js'>< / script>
< script type ='text / javascript'src ='http://localhost/ecommerce/js/lightview.js'>< / script>
< / head>
Code2:
< script type =text / javascript>
jQuery.noConflict();
jQuery(document).ready(function(){
// Esconde a div boleto
jQuery(#boleto)。css(display,none );
// Adiciona evento onclick no checkbox com o nome de boleto
jQuery(#cboleto)。click(function(){
jQuery.noConflict();
// se checado:
if(jQuery(#cboleto)。is(:checked)){
// mostra a div escondida
jQuery(# boleto)。show(fast);
} else {
// caso contrario,esconde
jQuery(#boleto)。hide(fast);
}
});
// esconde div签证
jQuery(#visa)。css(display,none);
// Adiciona evento onclick no checkbox com o nome de visa
jQuery(#cvisa)。click(function(){
jQuery.noConflict();
// se checado:
if(jQuery(#cvisa)。is(:checked)){
// mostra a div escondida
jQuery(#visa)。show( 快);
}其他{
// caso contrario,es conde
jQuery(#visa)。hide(fast);
}
});
// esconde一个div master
jQuery(#master)。css(display,none);
// Adiciona evento onclick no checkbox com o nome de master
jQuery(#cmaster)。click(function(){
jQuery.noConflict();
// se checado:
if(jQuery(#cmaster)。is(:checked)){
// mostra a div escondida
jQuery(#master ).show(fast);
} else {
// caso contrario,esconde
jQuery(#master)。hide(fast);
}
});
// esconde一个div pagseguro
jQuery(#pagseguro)。css(display,none);
// Adiciona evento onclick no checkbox com o nome de pagseguro
jQuery(#cpagseguro)。click(function(){
jQuery.noConflict();
// se checado:
if(jQuery(#cpagseguro)。is(:checked)){
// mostra a div escondida
jQuery(#pagseguro ).show(fast);
} else {
// caso contrario,esconde
jQuery(#pagseguro)。hide(fast);
}
});
});
< / script>
浏览器指出错误PROTOTYPE。
如何解决这个问题呢?
Thankz
<在这种情况下,您应该在其他脚本之后加载jQuery脚本。然后,在脚本的顶部,您应该只调用 jQuery.noConflict();
一次。大多数人会将 $
重新分配给其他人,例如 var $ j = jQuery;
你遇到问题的原因是因为Prototype试图使用已经与jQuery相关联的 $
变量。 / p>
有关详细信息,请参阅此页面: http:// docs .jquery.com / Using_jQuery_with_Other_Libraries
所以,你应该这样:
< HEAD>
< link rel =stylesheettype =text / csshref =http://localhost/ecommerce/css/lightview.css/>
< script type ='text / javascript'src ='http://ajax.googleapis.com/ajax/libs/prototype/1.6.1/prototype.js'>< / script>
< script type ='text / javascript'src ='http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.2/scriptaculous.js'>< / script>
< script type ='text / javascript'src ='http://localhost/ecommerce/js/lightview.js'>< / script>
< script type =text / javascriptsrc =http://localhost/ecommerce/js/jquery-1.3.2.min.js>< / script>
< script type =text / javascript>
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery(#boleto)。css(display,none);
jQuery(# cboleto)。click(function(){
/ * notice,jQuery.noConflict();不需要在这里* /
if(jQuery(#cboleto)。is( :选中)){
jQuery(#boleto)。show(fast);
} else {
jQuery(#boleto)。hide(fast) ;
}
});
/ *然后你剩下的代码* /
});
< / script>
< / head>
Friends I have a problem with jquery and prototype:
<head>
<link rel="stylesheet" type="text/css" href="http://localhost/ecommerce/css/lightview.css" />
<script type="text/javascript" src="http://localhost/ecommerce/js/jquery-1.3.2.min.js" ></script>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/prototype/1.6.1/prototype.js'></script>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.2/scriptaculous.js'></script>
<script type='text/javascript' src='http://localhost/ecommerce/js/lightview.js'></script>
</head>
Code2:
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function(){
//Esconde a div boleto
jQuery("#boleto").css("display","none");
//Adiciona evento onclick no checkbox com o nome de boleto
jQuery("#cboleto").click(function(){
jQuery.noConflict();
//se checado:
if (jQuery("#cboleto").is(":checked")){
//mostra a div escondida
jQuery("#boleto").show("fast");
}else{
//caso contrario, esconde
jQuery("#boleto").hide("fast");
}
});
//esconde a div visa
jQuery("#visa").css("display","none");
//Adiciona evento onclick no checkbox com o nome de visa
jQuery("#cvisa").click(function(){
jQuery.noConflict();
//se checado:
if (jQuery("#cvisa").is(":checked")){
//mostra a div escondida
jQuery("#visa").show("fast");
}else{
//caso contrario, esconde
jQuery("#visa").hide("fast");
}
});
//esconde a div master
jQuery("#master").css("display","none");
//Adiciona evento onclick no checkbox com o nome de master
jQuery("#cmaster").click(function(){
jQuery.noConflict();
//se checado:
if (jQuery("#cmaster").is(":checked")){
//mostra a div escondida
jQuery("#master").show("fast");
}else{
//caso contrario, esconde
jQuery("#master").hide("fast");
}
});
//esconde a div pagseguro
jQuery("#pagseguro").css("display","none");
//Adiciona evento onclick no checkbox com o nome de pagseguro
jQuery("#cpagseguro").click(function(){
jQuery.noConflict();
//se checado:
if (jQuery("#cpagseguro").is(":checked")){
//mostra a div escondida
jQuery("#pagseguro").show("fast");
}else{
//caso contrario, esconde
jQuery("#pagseguro").hide("fast");
}
});
});
</script>
The Browser points out the error PROTOTYPE.
How can I fix this where the solution?
Thankz
Felipe, in this situation, you should load your jQuery scripts after your other scripts. Then, at the top of your scripts, you should call jQuery.noConflict();
only once. Most would reassign the $
at that point to something else, for instance var $j = jQuery;
The reason you're having problems is because Prototype is trying to use the $
variable, which is already associated with jQuery.
See this page for more information: http://docs.jquery.com/Using_jQuery_with_Other_Libraries
So, you should have this:
<head>
<link rel="stylesheet" type="text/css" href="http://localhost/ecommerce/css/lightview.css" />
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/prototype/1.6.1/prototype.js'></script>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.2/scriptaculous.js'></script>
<script type='text/javascript' src='http://localhost/ecommerce/js/lightview.js'></script>
<script type="text/javascript" src="http://localhost/ecommerce/js/jquery-1.3.2.min.js" ></script>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery("#boleto").css("display","none");
jQuery("#cboleto").click(function(){
/* notice, jQuery.noConflict(); doesn't need to be here */
if (jQuery("#cboleto").is(":checked")){
jQuery("#boleto").show("fast");
}else{
jQuery("#boleto").hide("fast");
}
});
/* Then the rest of your code */
});
</script>
</head>
这篇关于问题jQuery和Prototype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!