英文:
how to disable this clickable module after clicking once.....that button should remain disabled after refreshing tha page
问题
<a href="oaccept1.php?id=<?php echo $data['oaid'];?>" class="btn btn-sm btn-primary login-submit-cs"
onclick="return confirm('Are You Sure')">接受</a>
要在接受后禁用该按钮,并且在接受文档后保持禁用状态。
英文:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<a href="oaccept1.php?id=<?php echo $data['oaid'];?>" class="btn btn-sm btn-primary login-submit-cs"
onclick="return confirm('Are You Sure')">ACCEPT</a>
<!-- end snippet -->
want to disable that button after accepting that and it should stay disabled after accepting that doc
答案1
得分: 1
使用服务器端,不要仅依赖JavaScript。
在表格中添加一个新字段名为 accepted
,并默认设置为假:
ALTER TABLE `tbl_name` ADD `accepted` BOOLEAN DEFAULT FALSE;
在点击接受按钮事件函数时,将此字段设置为真:
INSERT INTO `table_name` (id, accepted) VALUES ('2', TRUE);
然后在您的PHP中使用:
<?php if ($data['accepted'] == FALSE) { ?>
<a href="oaccept1.php?id=<?php echo $data['oaid']; ?>" class="btn btn-sm btn-primary login-submit-cs" onclick="return confirm('Are You Sure')">ACCEPT</a>
<?php } else { ?>
<a class="btn btn-sm btn-primary login-submit-cs" disabled>ACCEPT</a>
<?php } ?>
希望这能帮助您。
英文:
Use server side, don't depend on only javascript
In table add new field as accepted
and make it false by default,
ALTER TABLE `tbl_name` ADD `accepted` BOOLEAN default false;
on click of accept button event function, set this field as true
INSERT INTO `table_name`(id, accepted) VALUES ('2',true );
Then in your php have
<?php if($data['accepted']==false){?>
<a href="oaccept1.php?id=<?php echo $data['oaid'];?>" class="btn btn-sm btn-
primary login-submit-cs"
onclick="return confirm('Are You Sure')">
ACCEPT
</a>
<?php }else {?>
<a class="btn btn-sm btn-
primary login-submit-cs"
disabled>
ACCEPT
</a>
<?php }?>
hope this will help you
答案2
得分: 0
我建议你将它变成一个按钮,否则谷歌爬虫的简单访问将接受所有内容。
另一种方法是使用表单提交事件。
英文:
I suggest you make it a button, otherwise a simple visit from a google bot will accept all
Alternative is to use a form submit event
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
window.addEventListener("DOMContentLoaded", () => {
const sub = document.querySelector(".login-submit-cs");
const dis = false; // localStorage.getItem("submitted"); // remove "false; //" to activate
if (!dis) sub.removeAttribute("disabled");
sub.addEventListener("click", (e) => {
let tgt = e.target.closest("button"); // using closest in case the element has children
if (!tgt || dis) return; // not the link
setTimeout(() => tgt.setAttribute("disabled","disabled"),200); // allow the button to be pressed
// localStorage.setItem("submitted",true); // remove comment lines to activate
location = tgt.dataset.href;
});
});
<!-- language: lang-html -->
<button data-href="oaccept1.php?id=<?php echo $data['oaid'];?>" class="btn btn-sm btn-primary login-submit-cs" disabled>ACCEPT</button>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论