我在PHP脚本的eho的“ a”标签内调用函数“添加”时遇到问题。单击后,按钮功能无法调用。我什么都不知道如何解决?
<?php
require_once 'connect.php';
$statement=$db->query('SELECT * FROM Items');
foreach($statement as $row)
{
$item="item_".$row[0];
$view="view".$row[0];
$image=$row[1];
$name=$row[2];
$price=$row[3];
$plus="+";
$minus="-";
echo "<tr>
<td class='cart_product'>
<a href=''><img src='images/cart/$image' alt=''></a>
</td>
<td class='cart_description'>
<h4><a href=''>$name</a></h4>
</td>
<td class='cart_price'>
<p>$$price</p>
</td>
<td class='cart_quantity'>
<div class='cart_quantity_button'>
<a class='cart_quantity_up' href='' onclick='adding($plus, $item);'> + </a>
<input class='cart_quantity_input' type='text' name=$item id=$item value='0' autocomplete='off' size='2'>
<a class='cart_quantity_down' href='javascript:adding($minus, $item); sumitem($item, $price, $view);'> - </a>
</div>
</td>
<td class='cart_total'>
<p style='width: 5em' class='cart_total_price' id=$view >$0</p>
</td>
<td class='cart_delete'>
<a class='cart_quantity_delete' href='javascript:reset($item, $view)'><i class='fa fa-times'></i></a>
</td>
</tr>";
}
?>
答案 0 :(得分:2)
您可以像这样调用JavaScript函数并向其发送变量:
<script>
function myFunc(var1){
alert(var1);
}
</script>
<?php
$var1= "\"test string\"";
echo "<a href='' onclick='myFunc($var1);'>Link to Click</a>";
?>
您的变量发送错误。