1. <tfoot id='uVt0e'></tfoot>

      1. <small id='uVt0e'></small><noframes id='uVt0e'>

          <bdo id='uVt0e'></bdo><ul id='uVt0e'></ul>

      2. <legend id='uVt0e'><style id='uVt0e'><dir id='uVt0e'><q id='uVt0e'></q></dir></style></legend>
      3. <i id='uVt0e'><tr id='uVt0e'><dt id='uVt0e'><q id='uVt0e'><span id='uVt0e'><b id='uVt0e'><form id='uVt0e'><ins id='uVt0e'></ins><ul id='uVt0e'></ul><sub id='uVt0e'></sub></form><legend id='uVt0e'></legend><bdo id='uVt0e'><pre id='uVt0e'><center id='uVt0e'></center></pre></bdo></b><th id='uVt0e'></th></span></q></dt></tr></i><div id='uVt0e'><tfoot id='uVt0e'></tfoot><dl id='uVt0e'><fieldset id='uVt0e'></fieldset></dl></div>

        Yii2 $this->registerJs($js);如何在 $js 中传递 php 变量

        时间:2023-10-15
      4. <legend id='OEwR5'><style id='OEwR5'><dir id='OEwR5'><q id='OEwR5'></q></dir></style></legend>

          <tbody id='OEwR5'></tbody>
            <i id='OEwR5'><tr id='OEwR5'><dt id='OEwR5'><q id='OEwR5'><span id='OEwR5'><b id='OEwR5'><form id='OEwR5'><ins id='OEwR5'></ins><ul id='OEwR5'></ul><sub id='OEwR5'></sub></form><legend id='OEwR5'></legend><bdo id='OEwR5'><pre id='OEwR5'><center id='OEwR5'></center></pre></bdo></b><th id='OEwR5'></th></span></q></dt></tr></i><div id='OEwR5'><tfoot id='OEwR5'></tfoot><dl id='OEwR5'><fieldset id='OEwR5'></fieldset></dl></div>

            <small id='OEwR5'></small><noframes id='OEwR5'>

            • <bdo id='OEwR5'></bdo><ul id='OEwR5'></ul>

                <tfoot id='OEwR5'></tfoot>
                  本文介绍了Yii2 $this->registerJs($js);如何在 $js 中传递 php 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  以下是我认为的 ajax 脚本.

                  Below is my ajax script in my view.

                  $js = <<< JS
                      $('.list-link').click(function(){
                          $.ajax({
                              url: '?r=public/getlist&param1=01&param2=02&param3=03',
                              dataType: "json",
                              success: function(data) {
                                  $(".well").html(data.id);                
                              }
                          })
                      });
                  JS;
                  $this->registerJs($js);
                  

                  现在我的问题是我将如何使 param1、param2 和 param3 的值动态化,就像我要将 params1 从 php 变量传递给 3 一样.

                  Now my problem is how am I going to make the values of param1, param2 and param3 dynamic like I am going to pass the params1 to 3 from php variables.

                  推荐答案

                  你可以这样做:

                  $url = yiihelpersUrl::to([
                      'public/getlist', 
                      'param1' => '01', 
                      'param2' => '02', 
                      'param3' => '03'
                  ]);
                  
                  $js = <<< JS
                      $('.list-link').click(function(){
                          $.ajax({
                              url: $url,
                              dataType: "json",
                              success: function(data) {
                                  $(".well").html(data.id);                
                              }
                          })
                      });
                  JS;
                  $this->registerJs($js);
                  

                  当然,您也可以使参数的数量动态化,因为它只是一个传递给 Url::to().

                  Of course you can make the number of parameters dynamic as well since it is just an array that gets passed to Url::to().

                  关于使用的Heredoc(允许使用变量)语法的官方信息可以在此处.

                  Official info about the used Heredoc (which allows variable usage) syntax can be found here.

                  这篇关于Yii2 $this->registerJs($js);如何在 $js 中传递 php 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在yii2中实现单一搜索表单 下一篇:yii2 中单独位置的单选按钮组

                  相关文章

                  <small id='R6dhP'></small><noframes id='R6dhP'>

                    <bdo id='R6dhP'></bdo><ul id='R6dhP'></ul>
                  <i id='R6dhP'><tr id='R6dhP'><dt id='R6dhP'><q id='R6dhP'><span id='R6dhP'><b id='R6dhP'><form id='R6dhP'><ins id='R6dhP'></ins><ul id='R6dhP'></ul><sub id='R6dhP'></sub></form><legend id='R6dhP'></legend><bdo id='R6dhP'><pre id='R6dhP'><center id='R6dhP'></center></pre></bdo></b><th id='R6dhP'></th></span></q></dt></tr></i><div id='R6dhP'><tfoot id='R6dhP'></tfoot><dl id='R6dhP'><fieldset id='R6dhP'></fieldset></dl></div>

                  1. <tfoot id='R6dhP'></tfoot>
                    <legend id='R6dhP'><style id='R6dhP'><dir id='R6dhP'><q id='R6dhP'></q></dir></style></legend>