我有以下代码使按钮不可见,它工作了一秒钟,然后按钮又出现了。在同一页面上导航的链接 我试过“返回错误;”但是我的导航不起作用。
如何隐藏按钮?
JavaScript
function btn_hide(){
document.getElementById("btn_shfaqe").style.display="none";
}
html
<a href="?tip=fin&vid_id=0" onClick="btn_hide();">test1</a>
最佳答案
你必须做两件事;返回函数并返回false,像这样:
javascript
function btn_hide(){
document.getElementById("btn_shfaqe").style.display="none";
return false;
}
html
<a href="?tip=fin&vid_id=0" onClick="return btn_hide();">test1</a>
这是一个 DEMO
根据评论编辑
你最好在服务器端隐藏按钮,但如果你真的想使用 javascript,你可以在页面加载时这样做:
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
window.onload = function() {
var vid_id = getParameterByName('vid_id');
if (vid_id == 0 || vid_id == 5) {
document.getElementById("btn_shfaqe").style.display="none";
}
}
关于javascript - 单击时按钮不会消失(JavaScript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23005913/