php – 为什么这不起作用?如何使这项工作?
发布时间:2020-12-13 17:16:15 所属栏目:PHP教程 来源:网络整理
导读:这是我的 HTML和 PHP代码 Colorbox很好用,它也显示了按钮. //This is the Colorbox codediv style="display: none"div id="remove" h1Are you sure you wish to remove this product/h1 h2Enter Captcha below to confirm/h2 //Just a Captcha-like behavior
这是我的
HTML和
PHP代码
Colorbox很好用,它也显示了按钮. //This is the Colorbox code <div style="display: none"> <div id="remove"> <h1>Are you sure you wish to remove this product</h1> <h2>Enter Captcha below to confirm</h2> //Just a Captcha-like behavior <input type="text" value="<?php echo $captcha_value; ?>" id="display" readonly ><br /> <br> <input type="text" name="captcha" value="" id="input" maxlength=6/> <br> <br> </div> </div> //To Display all products <?php foreach ($products as $product) { ?> <td> <div> <img src="<?php echo $product['image']; ?>"/> </div> <div> <a onClick="loadColor(<?php echo $product['opv_id']; ?>)" class="remove-item"> <img src="<?php echo $product['product_remove_image']; ?>"/> </a> //To know which product's link was clicked </div> </td> <?php } ?> //loadColor function which will append a button to Colorbox <script type="text/javascript"> function loadColor(opv_id) { //To create a button and append to the colorbox and call colorbox $('#remove-product').remove(); string = '<button value="' + opv_id + '" id="remove-product">Submit</button>'; $(string).appendTo('#remove'); jQuery.colorbox({inline: true,href:"#remove",width:"50%"}); } </script> <script type="text/javascript"> $('#remove-product').click(function() { alert('Clicked'); //Do something here!! }) </script> 得到它了 :) 那么有没有其他更简单的方法来实现我上面尝试做的事情? 解决方法
您需要为动态添加的元素使用事件委派:
$('#remove').on("click",'#remove-product',function () { alert('Clicked'); //Do something here!! }); 检查documentation (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |