我正在创建一个弹出窗口。我正在使用花式盒子,当我将其通常包含在 html 中时,它工作正常,如下所示:
<script type="text/javascript">
$(document).ready(function($){
$.fancybox.open([{
content: $('<a href="http://www.google.com" target="_blank">Gmail</a>')
}]);
});
</script>
但是当我用drupal_add_js写同样的报价时,它不起作用:
drupal_add_js('jQuery(document).ready(function(){
$.fancybox.open([{
content: $("<a href=''http://www.google.com'' target=''_blank''>Gmail</a>")
}]);
});','inline');
我将其作为内联java脚本传递,有人可以告诉我它发生的错误是什么。我已经包含了花哨的盒子js和css。
我相信drupal在jQuery上设置了noConfilct,所以你必须将ready函数的参数设置为$
drupal_add_js('jQuery(document).ready(function($){
$.fancybox.open([{
content: $("<a href=''http://www.google.com'' target=''_blank''>Gmail</a>")
}]);
});','inline');
它终于对我有用了。我明确地使用drupal_Add_js函数调用了 js 文件,其余所有代码都是一样的。按照我的要求,它的工作绝对很好。非常感谢您的帮助。
drupal_add_js('jquery.fancybox.js');
drupal_add_js('http://code.jquery.com/jquery-1.7.2.js');
drupal_add_js('jQuery(document).ready(function(){
$.fancybox.open([{
content: $("<a href=''http://www.google.com'' target=''_blank''>Gmail</a>")
}]);
});', 'inline');