-1

我对 javascript 了解不多,也没有任何朋友知道 javascript :( 这就是为什么我再次向 stackoverflow 社区寻求帮助。我的脚本有一个新模板,但问题是我有一些我的脚本与模板中的某些 js 一起工作所需的prototype.js 发生冲突,我不知道如何解决这个问题,因为没有注释 js 模板将无法正常工作,主 js 和脚本不会在没有原型 js 的情况下正常工作我不知道是否有人有时间查看脚本并可能给出合并它们的解决方案,因为是大脚本,最后我会尝试。

我已经在某些位置上传了脚本并将链接放在这里

pastebin.com/n5dnr6i7 here is the main.js required for template

pastebin.com/YisnTuBM comments.js recuired for template

pastebin.com/Cibn1NA2 prototype.js required for main script  

注释和 main 在加载原型时无法正常工作

先感谢您!

编辑:我很抱歉在 Java 中发布此内容,感谢您的更正

编辑2:问题是网络脚本是用IonCube加密的,我只能访问模板html文件,这有点复杂,因为模板是我使用的网络脚本的修改/破解版本,它是一个视频管脚本,例如我使用的原始 web 脚本使用包含在 video.html 中的 comments.html 破解/修改是不同的,我必须在新的 video.html 模板中包含旧的 comments.html 文件,现在如果我使用jquery-1.9.1,当我点击它时,评论区框会向下滑动,但如果我使用原型,我无法评论视频,我可以评论视频,但评论区框被冻结,它不会向下滑动我点击它,我不知道如何合并它们

4

1 回答 1

0

我已将这些文件添加到 jsfiddle,您确定甚至需要 Prototype 吗?我已将其注释掉并替换为 jQuery(因为注释文件似乎需要它,组合的 [main] 文件也需要它)。

这样做后,我在页面加载时没有错误。

<!-- prototype -->
<!--script src="http://pastebin.com/raw.php?i=Cibn1NA2"></script-->

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<!--script>jQuery.noConflict();</script-->

<!-- comments -->
<script src="http://pastebin.com/raw.php?i=YisnTuBM"></script>

<!-- main = Modernizr + extras -->
<script src="http://pastebin.com/raw.php?i=n5dnr6i7"></script>

编辑评论: 第二小提琴展示 jQuery 的使用noConflict()

设置 - 要么不注释两个脚本标签,要么尝试注释一个或另一个,看看你得到了哪些错误。

测试使用addClassjQuery 的addClassName函数和 Prototype 的函数来查看哪个版本$处于活动状态。一种或其他方法将失败,具体取决于当时哪种$方法处于活动状态。

<!-- Comment one of these script tags, or leave both uncommented for noConflict mode -->
<!-- jQuery must come second in order to properly use noConflict -->
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

测试:

// local var for jQuery - this might be undefined if jQuery not imported
var jQuery = window["jQuery"];
// if jQuery exists, put into noConflict mode - i.e. return jQuery $ to Prototype $
if (jQuery) jQuery.noConflict();

try {
    // addClassName is prototype only, not jquery
    $("output").addClassName("prototype");
    setOutput("$.addClassName ok");
} catch (e) {
    setOutput("Prototype > $.addClassName error: " + e);
}

try {
    // addClass is jquery only, not prototype
    $("output").addClass("jquery");
    setOutput("$.addClass ok");
} catch (e) {
    setOutput("jQuery > $.addClass error: " + e);
}

try {
    // try using jQuery with the 'full' jQuery name
    jQuery("output").addClass("jquery");
    setOutput("jQuery.addClass ok");
} catch (e) {
    setOutput("jQuery > jQuery.addClass error: " + e);
}

// wrap the code that needs $ to be jQuery $ in a function.
// and pass in jQuery to be aliased as $ within the function.
(function($) {
    try {
        $("output").addClass("jquery");
        setOutput("$.addClass ok when wrapped");
    } catch (e) {
        setOutput("jQuery > wrapped $.addClass error: " + e);
    }
}(jQuery));

包含 Prototype 和 jQuery 时的示例输出:

$.addClassName ok
jQuery > $.addClass error: TypeError: $(...).addClass is not a function
jQuery.addClass ok
$.addClass ok when wrapped
于 2013-04-05T17:57:29.037 回答