Home > php教程 > php手册 > body text

THINKPHP的U方法带入JS变量的解决方案

WBOY
Release: 2016-06-07 11:36:32
Original
1244 people have browsed it

我想很多小伙伴都有过这样的困惑吧,反正我是被困惑了好久,用TP在写联动功能的时候,会纠结怎么才能将用js获取来的上级ID用U方法传递到控制器的方法里,来获取下级列表。再返回到页面。就像省份和城市这种,切换省份要获取响应省份下的城市这种。我个人觉得我的方法还可以,所以跟大家交流分享一下。
先将JS变量以字符串的形式带入到U方法,后用js替换函数将其替换成JS变量就OK啦。var province_id = 3;//要带入的变量<br> var str = "{:U('article/getCity',array('pid'=>'province_id'))}"; //先将变量以字符串的形式带入U函数中<br> str1 =  str.replace("province_id",province_id); //将代替变量的字符串用真实变量替换掉,OK搞定!<br> $("#city_id").load(str1);

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template