PHP按钮onclick=";this.disabled=true";如果页面刷新,则取消设置
我不想取消设置onclick=“this.disabled=true”如果页面刷新 代码:PHP按钮onclick=";this.disabled=true";如果页面刷新,则取消设置,onclick,Onclick,我不想取消设置onclick=“this.disabled=true”如果页面刷新 代码: <button type="button" class="addb btn btn-primary rounded-pill py-2 btn-block" type="submit" data-voice_sku="'.$row["voice_sku"].'" data-voice_name="'.$row["voice_name"].'" onclick="this.disabled=true
<button type="button" class="addb btn btn-primary rounded-pill py-2 btn-block" type="submit" data-voice_sku="'.$row["voice_sku"].'" data-voice_name="'.$row["voice_name"].'" onclick="this.disabled=true">Add to Playlist</button>
添加到播放列表
如果页面刷新onclick事件未设置。如何预防?我会使用本地存储来实现这一点。以下是一个基本示例:
<button id="myBtn" type="button" onclick="disable_btn(this);">Add to Playlist</button>
<script>
// disable the button on page load
(function() {
if(window.localStorage.getItem('myBtn') == 'true'){
document.getElementById('myBtn').disabled=true;
}
})();
// function to disable button when clicked
function disable_btn(el){
el.disabled=true;
window.localStorage.setItem('myBtn', true);
}
</script>
添加到播放列表
//禁用页面加载按钮
(功能(){
if(window.localStorage.getItem('myBtn')='true'){
document.getElementById('myBtn')。disabled=true;
}
})();
//单击时禁用按钮的功能
功能禁用\u btn(el){
el.disabled=真;
window.localStorage.setItem('myBtn',true);
}
以及多个按钮的示例:
<button id="btn1" type="button" onclick="disable_btn(this, 'btn1');">Add to Playlist 1</button>
<button id="btn2" type="button" onclick="disable_btn(this, 'btn2');">Add to Playlist 2</button>
<button id="btn3" type="button" onclick="disable_btn(this, 'btn3');">Add to Playlist 3</button>
<script>
// disable disabled buttons on page load
(function() {
var buttons = document.querySelectorAll('button')
for (var i = 0; i < buttons.length; ++i) {
if(window.localStorage.getItem(buttons[i].id) == 'true'){
buttons[i].disabled=true;
}
}
})();
// function to disable button when clicked
function disable_btn(el, id){
el.disabled=true;
window.localStorage.setItem(id, true);
}
</script>
添加到播放列表1
添加到播放列表2
添加到播放列表3
//禁用页面加载上的禁用按钮
(功能(){
var buttons=document.querySelectorAll('按钮')
对于(变量i=0;i
这样,该用户的禁用按钮将始终保持禁用状态,除非他清除浏览器缓存。不工作,我的按钮:添加到播放列表将此按钮添加到您的按钮:id=“myBtn”