1. 程式人生 > >Thinkphp5中利用js/jQuery傳遞參數的方法

Thinkphp5中利用js/jQuery傳遞參數的方法

傳遞參數 ati array key win comment 字符串 num pid

window.location.href="{:url(‘Index/index‘)}>"+"/ID/"+ID; //這樣可以生成,但url模式改變則不能用

window.location.href="{:url(‘Index/index‘,‘ID=" + ID+ "‘)}" //解析不成功。

window.location.href="{:url(‘Index/detail‘,[‘id‘ => "+iD+"])}";//解析不成功

window.location.href=‘{:url("Index/detail")}?id=‘+ iD ;//解析成功

另外一種方法:

var pid = 3;//要帶入的變量

var str = "{:url(‘Index/detail‘,array(‘id‘=>‘p_id‘))}"; //先將變量以字符串的形式帶入U函數中

str1 = str.replace("P_id",pid); //將代替變量的字符串用真實變量替換掉,OK搞定!

$("#city_id").load(str1);

或者

var pid = 3;

var str = "{:url(‘Index/detail‘)}";

$("#city_id").load(str, {"id" : pid});

Thinkphp5中利用js/jQuery傳遞參數的方法