2013-01-11 74 views
0

我有jQuery功能,動態地添加a,當我想要使用此元素作爲模式我不能,沒有任何反應。模式窗口不顯示在Joomla

當我添加相同的元素使用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) 
        ))); 
       }); 
+0

如果這沒有幫助,確保你中有你正確的編碼文件view.html.php像這樣? – Diego

+0

在開始的HTML tmpl – Viszman

+0

你可以使用另一種方式來模型窗口http://www.spiralscripts.co.uk/Joomla-Tips/using-modal-windows-with-joomla.html http://www.kirbymixedmedia的.com /黑客-的MainMenu-30/16的Joomla/36的負載mootools的模態窗口-立即合的Joomla –

回答

0

確保你只有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"); 
    } 
?> 

顯然改變,因此無論適合您需要的路徑。如果您使用的是`jQuery.modal`

$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);