简体   繁体   English

Drupal 7 jQuery块显示为文本

[英]Drupal 7 jquery block displaying as text

I'm having a lot of trouble adding a jQuery block. 我在添加jQuery块时遇到很多麻烦。 I've searched every forum and tried a ton of solutions but no matter what it always ends up displaying as html text in the header. 我已经搜索了每个论坛,并尝试了很多解决方案,但是无论它最终以什么样的形式显示在标头中,这都是无关紧要的。

Is there anything wrong with the code I've written in the block? 我在块中编写的代码有什么问题吗?

<script type="text/javascript">

(function ($) {

   var leftInit = $("#logo-scroll").offset().left;
   var top =$("#logo-scroll").offset().top;

   $(window).scroll(function(event) {
    var x = 0 - $(this).scrollLeft();
    var y = $(this).scrollTop();

    $("#logo-scroll").offset({
    left: x + leftInit
    });

});

})(jQuery);


</script>

If I call upon the library it displays that as html as well, but it appears to be already called upon when I inspect the page and my code doesn't look any different than other js or jq blocks that are already built and being used. 如果我调用该库,它也将其显示为html,但是当我检查该页面时,它似乎已经被调用过,并且我的代码看起来与已构建并正在使用的其他js或jq块没有任何不同。

Granted I'm not very familiar with jQuery, but it works in jsfiddle http://jsfiddle.net/F7Bme/1184/ 当然,我对jQuery不太熟悉,但是它可以在jsfiddle中使用http://jsfiddle.net/F7Bme/1184/

I have no access to the backend .js files, so it has to be put into a block. 我无权访问后端.js文件,因此必须将其放在一个块中。

Any guidance would be appreciated, this is frustrating me to no end. 任何指导将不胜感激,这使我无休止。

FULL HTML does not work with Javascript. 完整HTML不适用于Javascript。

You will need to enable the core PHP Filter module, and then you can change the input format to PHP code, and everything will work as you desire (providing your javascript code is correct). 您将需要启用核心PHP过滤器模块,然后可以将输入格式更改为PHP代码,然后一切都会按您希望的方式工作(前提是您的javascript代码正确)。

The full html filter does not allow for javascript. 完整的html过滤器不允许使用javascript。

This said now, you might want to include any extra javascript like this in a .js include file with your theme. 这就是说,您可能想要在主题的.js包含文件中包含任何此类额外的javascript。

I just tried your code in a block on a D7 site and it did not display in the HTML. 我只是在D7网站上的一个块中尝试了您的代码,但它没有显示在HTML中。 I had Full HTML selected as the formatting. 我选择了Full HTML作为格式。 If the formatting somehow got set to Filtered, etc, that would produce the problem you are having. 如果格式化以某种方式设置为“已过滤”等,则会产生您遇到的问题。

Update: here is a screenshot from Firebug. 更新:这是Firebug的屏幕截图。 I also tested a basic document.write("hello");in the same block, and it rendered on the page as expected. 我还在同一块中测试了一个基本document.write(“ hello”);并按预期将其呈现在页面上。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM