如何将值传递给 onclick 函数

我正在做网上购物项目。从Add to cart我想使用onclick函数发送多个 ProductID。


$id="";

foreach ($data['product id'] as $key => $value) {

   $id .= $value->Product ID;

我得到了所有的 id $id。如何在onclick函数中传递这个值。


<a href="JavaScript:void(0);" onclick="'.site_url().'checkout/Addcarts/'.$id.'

错误:未捕获的语法错误:输入意外结束


繁华开满天机
浏览 144回答 2
2回答

当年话下

您可以使用onclick="activeasheesh('.&nbsp;"'"&nbsp;.&nbsp;$newproject->fld_id&nbsp;.&nbsp;"','"&nbsp;.&nbsp;$newproject->proj_id&nbsp;.&nbsp;"'".')"

繁花如伊

最好使用ajax。如下图创建超链接&nbsp; &nbsp; <a href="JavaScript:void(0);" onclick="submit_id(<?= $id ?>)">创建一个jQuery函数,如下所示&nbsp; &nbsp; function submit_id(id) {&nbsp; &nbsp; &nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: "<?= site_url(); ?>checkout/Addcarts/" + id,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "POST",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: function(data) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(data);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error: function(request) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(request.statusText);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP