1

我正在尝试将 div 附加到网站的正文,然后在用户使用 jquery 单击关闭按钮时将其向左滑动来隐藏它。该站点当前使用 Drupal 7,由于多种原因,直接编辑文件是不可能的。我正在使用 Optimizely 来应用它。

我知道我需要应用正确的 jquery 函数,但我的主要问题是弄清楚如何从 Optimizely 将 jQuery UI 添加到我的文档中,以便它适用于我在编辑代码部分中添加的 jQuery 代码。这是我想要附加的 div 的内容,将 jQuery .hide 函数应用于按钮标签:

$("body").append("<div id=\"faceboxwrap\">
<div id=\"facebox\" style=\"height:500px; width:320px; z-index:99999; position:fixed; margin-left:0px; bottom:20px; background-image:url(..);\">
<div class=\"action-link field-name-field-fa-link\" style=\"float:left; margin-top:360px; padding-right: 10px; \">
<div class=\"field field-name-field-shared-splash-link field-type-link-field field-label-hidden\" style=\"width: 175px; margin-left: 103px; margin-right: auto; top: 38px; background-color: rgb(204, 51, 51); \">
<div class=\"field-items\">
<div class=\"field-item even\">
<a href=\"...\" id=\"trackDonate\" style=\"padding-right: 10px;\">DONATE $10</a>
</div></div></div>\n
<div style=\"text-align: center; width: 100%; color: rgb(121, 121, 121); font-size: 13px; margin-top: 60px; margin-left: 115px;\">
<button id=\"close\" style=\"font-weight: bold; font-size: 14px; cursor: pointer; text-transform: lowercase; cursor: hand;\" onclick=\"$('#faceboxwrap')hide('slide', {direction: 'left'}, 1000));\"> No thanks </button>
</div></div></div></div>");

有没有办法在不编辑实际网站的情况下将 jQuery UI 脚本应用到这个 div?我要添加的javascript源是:http ://code.jquery.com/ui/1.10.4/jquery-ui.js

我试图用这段代码应用它,但它没有用:

$(function(){var fileRef1 = document.createElement('script'); 
fileRef1.setAttribute("type","text/javascript"); 
fileRef1.setAttribute("src","http://code.jquery.com/ui/1.10.4/jquery-ui.js"); 
document.head.appendChild(fileRef1);});

四个多小时以来,我一直在尝试用我能找到的每一个技巧来做到这一点,但我无法让它发挥作用。任何帮助都会很棒。谢谢。

4

1 回答 1

2

我想通了。我需要改变

onclick=\"$('#faceboxwrap').hide('slide', {direction: 'left'}, 1000));\"

onclick=\"jQuery('#faceboxwrap').hide('slide', {direction: 'left'}, 1000));\"
于 2014-01-31T15:33:50.487 回答