[英]HTML div with jquery on.click not working as expected
Good day i have an html div written below.美好的一天,我在下面写了一个 html div。
.SubmitOrder { height: 60px; width: 200px; margin-top: 10px; margin-right: 30px; float: right; background: #C40514; text-align: center; display: block; }
<head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <div class="SubmitOrder"> <?php echo "Total: ".$totalPrice."<br> Pay Now!" ?> <script> $('.SubmitOrder').on('click', function() { window.location.replace(<?php echo "home.php?account_id=$accountid" ?>); }) </script> </div>
But upon clicking the div it does not redirect me to the link.但是在单击 div 时,它不会将我重定向到链接。 Am I doing something wrong?
难道我做错了什么?
It will be better to place your script inside the head
part using the ready
function will assure that all the targeted elements inside your script are loaded.最好使用
ready
函数将脚本放在head
部分中,以确保加载脚本中的所有目标元素。
NOTE : You must also wrap the new link <?php echo "home.php?account_id=$accountid" ?>
in single quotes ''
.注意:您还必须将新链接
<?php echo "home.php?account_id=$accountid" ?>
用单引号''
括起来。
window.location.replace('<?php echo "home.php?account_id=$accountid" ?>');
.SubmitOrder { height: 60px; width: 200px; margin-top: 10px; margin-right: 30px; float: right; background: #C40514; text-align: center; display: block; }
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $(function() { $('.SubmitOrder').on('click', function() { window.location.replace('<?php echo "home.php?account_id=$accountid" ?>'); }); }); </script> </head> <body> <div class="SubmitOrder"> Total: 1000$ <br> Pay Now! </div> </body> </html>
try this for javascript试试这个 javascript
<div class="SubmitOrder">
<?php echo "Total: ".$totalPrice."<br> Pay Now!" ?>
</div>
<script>
$('.SubmitOrder').on('click', function() {
window.location.replace(<?php echo "home.php?account_id=$accountid" ?>);
})
</script>
move script tag out of div with class SubmitOrder
使用类
SubmitOrder
将脚本标签移出 div
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.