gpt4 book ai didi

javascript - 在同一页面中同时使用 Prototype 和 jQuery 时出现问题

转载 作者:行者123 更新时间:2023-11-28 11:27:35 25 4
gpt4 key购买 nike

当我使用 jquery 脚本作为内联窗口和原型(prototype)来切换菜单时,我遇到了冲突。当我使用两者之一时工作正常。然而,当我同时使用它们时,只有原型(prototype)可以工作。我读到了有关 jquery.noconflict 的内容,但我可以正确使用它。这些是脚本。

这是我的 jquery 脚本(内联窗口)

<script type="text/javascript">

$(document).ready(function(){

//When you click on a link with class of poplight and the href starts with a #
$('a.poplight[href^=#]').click(function() {
var popID = $(this).attr('rel'); //Get Popup Name
var popURL = $(this).attr('href'); //Get Popup href to define size

//Pull Query & Variables from href URL
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1]; //Gets the first query string value

//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('');

//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;

//Apply Margin to Popup
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});

//Fade in Background
$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer

return false;
});


//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove();
}); //fade them both out

return false;
});


});

</script>

这是我的原型(prototype)脚本

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script>  

<script type="text/javascript">
// <![CDATA[
// Making sure this code only executes when the document is loaded: this makes the DOM available to us
Event.observe(document, 'dom:loaded', function() {

// for every element with an toggler class...
$$('.toggleExample').each(function(element) {

// we put on an event listener of the click type
Event.observe(element, 'click', function(event){

// We stop the default link behaviour
Event.stop(event);

// when clicked, traverse the DOM: 1 step up (from it's A-element to it's container DIV-element),
// and select its following sibling (next(0)), and toggle that shit.
Event.element(event).up(0).next(0).toggle();

}, false);

});

});
// ]]>
</script>

最佳答案

将其放在嵌入的 jquery.js 之后:

<script  type="text/javascript">
$.noConflict();
</script>

并更改此行:

$(document).ready(function(){

jQuery(document).ready(function($){

关于javascript - 在同一页面中同时使用 Prototype 和 jQuery 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6272419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com