猿问

如何使按钮在按下后不可点击或隐藏

访客订阅后选择页面,或者进入后天,订阅按钮我不想给他看,因为他已经订阅了


炎炎设计
浏览 139回答 2
2回答

慕斯王

您需要在加载时隐藏它并在单击时隐藏它CSS.hide { display:none }脚本:var but = document.getElementById("#buttonID");// sets class onload if localStorage is setbut.classList.toggle("hide",localStorage.getItem("subscribed") != null); but.addEventListener("click",function() {  localStorage.setItem("subscribed","yes")   but.classList.add("hide");})

万千封印

至于安全原因,:visted伪不支持该display:none属性。对此的粗略答案是使用JQUERY并检查用户是否已经访问过,然后将类添加到其中,并且该类具有display:none以下工作解决方案的属性:<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><a href="http:/youtube.com">Subscribe Now</a>查询:$( document ).ready(function() {&nbsp; &nbsp; $("a").on('click', function(){&nbsp; &nbsp; &nbsp; &nbsp; var $this = $(this);&nbsp; &nbsp; &nbsp; &nbsp; localStorage.setItem($this.attr('href'), true);&nbsp; &nbsp; &nbsp; &nbsp; $this.addClass('visited');&nbsp; &nbsp; });&nbsp; &nbsp; &nbsp;$("a").each(function(index, elem){&nbsp; &nbsp; &nbsp; &nbsp; var item = $(elem);&nbsp; &nbsp; &nbsp; &nbsp; if (localStorage.getItem(item.attr('href'))){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item.addClass('visited');&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp; });CSS:&nbsp; .visited{&nbsp; &nbsp; display:none;&nbsp; }
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答