douxunchen3498 2017-09-01 14:03
浏览 31

使用href <a> onClick的PHP snackbar不起作用?

I'm trying to dismiss this snackbar when I click the add to cart <a href> but it doesn't output anything. Anyone can help me? here is my code

SNACKBAR CODE

<div id="snackbar">Some text some message..</div>

A HREF CODE

<a class="btn btn-primary" href="?add=<?php echo($i); ?>" onClick="myFunction()">Add to cart

JQUERY.JS CODE

function myFunction() {
var x = document.getElementById("snackbar")
x.className = "show";
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}
  • 写回答

2条回答 默认 最新

  • douyasihefu6214 2017-09-01 14:46
    关注

    Your code doesn't at all make use of jQuery. But if you want to use jQuery the code below is equivalent of jQuery code to your clean js code.

    function myFunction() {
        var snackbar = $("#snackbar");
        snackbar.addClass("show").delay(3000).removeClass("show");
    }
    

    Or even better:

    function myFunction() {
        var snackbar = $("#snackbar");
        snackbar.show().delay(3000).hide();
    }
    

    a jsfidle example her would have been good.

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探