简体   繁体   English

javascript 函数在 php echo 中不起作用

[英]javascript function didn't work at php echo

大家好,你能帮我吗?我想回显我的按钮,但似乎我的 JS onclick 功能无法工作

 echo "<th><button id="btnPrint" type="button" class="btn btn-primary " onclick="pindah('<?php echo $row->id ; ?>')">Detail Laptop &nbsp;<span class="fa fa-info"></span></button></th>"; 

(As stated by others already) You need to use the correct quotes. (正如其他人已经说过的)您需要使用正确的引号。 And concatenate your value instead of using <?php echo... when you already use echo to output:并连接您的值而不是使用<?php echo...当您已经使用echo输出时:

echo '<th><button id="btnPrint" type="button" class="btn btn-primary" onclick="pindah(' . $row->id . ')">Detail Laptop &nbsp;<span class="fa fa-info"></span></button></th>';

You need to escape the double quotes as the php statement is not completely error-free.您需要转义双引号,因为 php 语句并非完全没有错误。 Also please have a look at the below link for more details.另外,请查看以下链接以了解更多详细信息。

Link: echo and print in PHP链接:在 PHP 中回显和打印

 echo "<th><button id=\"btnPrint\" type=\"button\" class=\"btn btn-primary \" onclick=\"pindah('<?php echo $row->id ; ?>')\">Detail Laptop &nbsp;<span class=\"fa fa-info\"></span></button></th>";

It will not work.不起作用。 JS is a client side scripting language. JS 是一种客户端脚本语言。 we cannot execute php code in javascript.我们无法在 javascript 中执行 php 代码。 please change your code in such a way it will do a post back on click or will make AJAX request on click.请以这样的方式更改您的代码,它会在点击时回发或在点击时发出 AJAX 请求。

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

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