0

動的に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)
                    )));
                });
4

1 に答える 1

0

インポートする 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);
于 2013-01-11T17:05:56.243 に答える