我在将任何类型的变量从PHP传递到JavaScript时遇到问题。这是jsFiddle的一个简单例子。为什么它不返回我的字符串?将PHP变量传递给JavaScript
http://jsfiddle.net/funinabox/VkNe2/1/
<?php
//create php test string
$teststring = "mystring";
?>
//Convert Php string to JavaScript string
var testvar = <?php echo $teststring; ?> ;
//Display output of the array elements;
alert(testvar);
你缺少链接 – 2013-04-22 13:48:28
你忘了引号:var testvar =“<?php echo $ teststring;?>”;' – x4rf41 2013-04-22 13:50:13
你不能在jsfiddle上测试PHP。 '未捕获的SyntaxError:意外的令牌<' – jbabey 2013-04-22 13:50:48