在使用thinkphp开发项目中,须要使用js跳转连接,在js使用u方法获取连接地址,代码以下:
php
- <script>
- var sampleid = 1;
- window.location.href="{:U(MODULE_NAME.'/Likecloth/delete','sample_id="+sampleid+"')}";
- </script>
上面这样写法,感受没啥大问题,当跳转的地址url却成下面这样
/index.php?s=/Home/Likecloth/delete/sample_id/"+sampleid+".html
就是说U方法里没有解析js变量。
下面换一种方法以下:
html
- <script>
- var sampleid = 1;
- window.location.href="{:U(MODULE_NAME.'/Likecloth/delete/sample_id/"+sampleid+"')}";
- </script>
这样访问地址以下:
index.php?s=/Home/Likecloth/delete/sample_id/1.html
thinkphp