我有一个Web应用程序,其中包含许多将数据提交到MySQL数据库的表单。
在所有页面上我都有include 'settings.php';
所以无论我放在哪里都会出现在每一页(CSS链接,JS代码等)
什么是最好的JS代码,我可以放入我的settings.php文件,在所有页面上的每个按钮上放置一个"onClick"
事件。
我希望它能做到这一点:
onClick="this.disabled=true; this.value='Please Wait…';"
因此,在网站的所有表单中,点击的每个按钮都会显示Please Wait...
文字,直到表单提交为止
答案 0 :(得分:1)
显然,回答这个问题的大多数人从未听说过事件授权。
window.addEventListener("click",function(e) {
var t = e.srcElement || e.target;
if( !t.tagName) t = t.parentNode;
if( t.tagName == "INPUT" && t.type.toLowerCase() == "submit") {
t.disabled = true;
t.value = "Please wait...";
}
},false);
答案 1 :(得分:0)
你真的不应该使用onClick=...
而是通过JS绑定动作:
document.getElementById('element-id').onclick=function(){
alert('Hello World');
}
答案 2 :(得分:0)
// very simple with jQuery
$(document).on('click', 'button,input[type="button"],input[type="submit"]', function (e) {
var $this = $(this).prop('disabled', true);
if ($this.is('button')) {
$this.html('Please wait...');
} else {
$this.val('Please wait...');
}
});
答案 3 :(得分:0)
这样的事情应该这样做:
(function() {
var buttons = document.getElementsByTagName('button');
for (var i=0,len=buttons.length; i<len; i++) {
buttons[i].addEventListener('click', function() {
this.disabled = true;
this.innerHTML = "Please Wait...";
});
}
})();