简体   繁体   English

JS调用PHP页面中的函数-语法问题

[英]JS call to function in php page - syntax issue

HI i tring to call a js function in PHP file using echo ""; 我想使用echo "";在PHP文件中调用js函数echo ""; and it's not working, if I call it without the echo it's work, what am I missing here ? 而且它不起作用,如果我在没有echo的情况下调用它,那么我在这里错过了什么?

this way it's is work: 这样就可以了:

<a href='#' onClick='delfrmvbar("dlsyg","<?php echo $sgId;?>","<?php echo $sgId;?>")'>X</a>&nbsp;</span> 

and this way is not (I tried without the - ' sign) 并且这种方式不是(我尝试了不带-'号)

echo "<a href='#' onClick='delfrmvbar('dlsyg','$sgId','$sgId')'>X</a>&nbsp;</span>";

Your single quotes are the issue because you use single quotes to wrap the onclick attribute, but then use them again around the arguments. 问题是单引号是因为您使用单引号来包装onclick属性,然后在参数周围再次使用它们。

Example solution: use double quotes around the attribute and escape. 解决方案的示例:在属性周围使用双引号并将其转义。

echo "<a href='#' onClick=\"delfrmvbar('dlsyg','$sgId','$sgId')\">X</a>&nbsp;</span>";

This will render the HTML like below, which is syntactically correct: 这将呈现如下的HTML,在语法上是正确的:

<a href='#' onClick="delfrmvbar('dlsyg','xx','xx')">X</a>&nbsp;</span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM