这段代码的正确引号语法应该如何?
<?php
$cod="<div id='id1' onclick='xmlhttpPost(index.php?ajax="'this.id'") class='divazienda'>".$row[0];
?>
我的问题是我没有获取js的this.id的结果
最佳答案
试试这个:
$cod="<div id=\"id1\" onclick=\"xmlhttpPost('index.php?ajax=' + this.id);\" class=\"divazienda\">".$row[0];
转义双引号(对于每个 div 属性),因为它们位于 php 双引号内
当您将具有当前元素 id 的字符串传递到 onclick 函数时 - 字符串部分需要放在引号中,而变量部分需要放在引号之外
关于javascript - 使用 javascript 转义 php 字符,正确的语法引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33126648/