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});
生成url 带入多个参数:
Url::build('index/detail/5',['id'=>1,'name'=>'thinkphp']);
最后采取的方式: <button id="make_menu" class="btn btn-danger">多选生成菜单</button> $("#make_menu").click(function () { var span_text = $("#id_href_span").text(); window.location.href='{:url("AdminOauth/createmenu")}?checkbox_id='+ span_text ;//跳转传参 });