将字符 php 转义为 javascript ,正确的语法引号
escape the characters php with javascript inside,correct syntax quotes
这段代码的正确引号语法应该如何?
<?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 函数时 - 字符串部分需要用引号引起来,而可变部分需要用引号引起来
这段代码的正确引号语法应该如何?
<?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 函数时 - 字符串部分需要用引号引起来,而可变部分需要用引号引起来