我正在尝试将php字符串传递给javascript函数.php部分看起来像这样:
<?php
foreach ($friends as $key => $friend) {
// Extract the pieces of info we need from the requests above
$id = assertNumeric(idx($friend, 'id'));
$name = idx($friend, 'name');
// Here we link each friend we display to their profile
echo('
<li>
<a href="#" onclick="window.open(\'http://www.facebook.com/' . $id . '\')">
<img src="https://graph.facebook.com/' . $id . '/picture?type=square" alt="' . $name . '">'. $name . '
</a>
<form>
<input type="button" value="Meet" onclick="postMeet(. $name.)"/>
</form>
</li>');
}
?>
Run Code Online (Sandbox Code Playgroud)
javascript函数看起来像这样.如果我将$ key或$ id传递给函数但没有传递$ name,它的工作正常.有人有任何想法吗?我是php和javascript的新手.
<script type="text/javascript"> …Run Code Online (Sandbox Code Playgroud)