【问题标题】:modal window not showing in joomla模态窗口未在 joomla 中显示
【发布时间】:2013-01-11 12:05:18
【问题描述】:

我有 jQuery 动态添加 a 的函数,当我想将此元素用作模态时,我不能,没有任何反应。

当我使用php 添加相同的元素时,一切正常。

我猜jQuery.modal 没有看到这个元素,有没有办法解决这个问题?

我的函数如下所示:

$.each(respJSON, function(){
                    $('#poll-questions').append(
                        $('<li>').append(
                            $('<a>').attr('href', prefix + this.id).attr('class', 'modal')
                            .attr('rel', '{handler: "iframe", size:{x:600, y:500}}')
                                .append($('<span>').append(this.question)
                    )));
                });

【问题讨论】:

标签: jquery joomla joomla2.5


【解决方案1】:

确保您只导入了 1 个 jQuery 库。如果您有超过 1 个,请使用以下代码检查是否已经有一个库正在导入。如果有,不要包括你自己的,如果没有,包括你自己的:

<?php
  // load jQuery, if not loaded before
  if(!JFactory::getApplication()->get('jquery')){
     JFactory::getApplication()->set('jquery',true);
     $document = JFactory::getDocument();
     $document->addScript(JURI::root() . "templates/template_name/js/jquery-1.8.3.js");
  }
?>

显然改变路径,以便满足您的需求。

如果这没有帮助,请确保您已正确添加了 view.html.php 文件的代码,如下所示:

$doc = JFactory::getDocument(); //remove this line if it's already in the file
$js = '$.each(respJSON, function(){
          $("#poll-questions").append(
             $('<li>').append(
                $("<a>").attr("href", prefix + this.id).attr("class", "modal")
                   .attr("rel", "{handler: "iframe", size:{x:600, y:500}}")
                   .append($("<span>").append(this.question)
          ));
       });'
$doc->addScriptDeclaration($js);

【讨论】:

    猜你喜欢
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    相关资源
    最近更新 更多