请教如何把一个PHP数组放到这个JS里面啊

WBOY
Release: 2016-06-13 12:55:08
Original
855 people have browsed it

请问怎么把一个PHP数组放到这个JS里面啊?
........................................
foreach($category as $group) {
$groupselect.= "\n";
}
echo  <script><br /> var rowtypedata = [<br /> [<br /> [1,'', 'td25'],<br /> [1,'<input type="text" class="txt" size="12" name="groupnamenewadd[]">', ''],<br /> [1,'<select name="groupnamenewadd[]"><option value="<span style="color: #FF00FF;">$groupselect"><span style="color: #FF00FF;">$groupselect', ''],<br /> <br /> [1,'<input type="text" class="txt" size="12" name="groupurlnewadd[]">', '']<br /> ]<br /> ];<br /> </script>
EOT;


试了好多种写法。都不行。只好上来求助了。$groupselect怎么才能写到JS里面呢?


------解决方案--------------------
你已经瓶装好了字符串
$groupselect .= "";

那就直接放进去就是了
....
[1,'', ''],

------解决方案--------------------
foreach里groupselect包含option了,下面还用option?
------解决方案--------------------
<br />
<script type="text/JavaScript"><br />
 var rowtypedata = [<br />
 [<br />
 [1,'', 'td25'],<br />
 [1,'<input type="text" class="txt" size="12" name="groupnamenewadd[]">', ''],<br />
 [1,'<select name="groupnamenewadd[]"><?php $groupselect ?></select>', ''],<br />
 <br />
[1,'<input type="text" class="txt" size="12" name="groupurlnewadd[]">', '']<br />
 ]<br />
 ];<br />
 </script><br />
Copy after login

------解决方案--------------------
引用:
引用:JavaScript code?1234567891011<script> var rowtypedata = [ [ [1,'', 'td25'], [1,'<input type="text" class="txt" size="12" name="groupnamenewadd……</script>

[1,'', ''],并贴出你的测试结果
------解决方案--------------------
你应该先组成一数组,然后这样,
var rowtypedata = ;

像你这样拼的话要注意单双引号

你上面是用单引号,$groupselect有单引号的话,js就出错了。
------解决方案--------------------
补充下
var str='';
var arr=eval('('+str+')');
看下arr是不是你想要的js数组
------解决方案--------------------
如果上面的不对试试这样
var str=;
var arr=eval(str);
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template