jQuery的简单修改,禁用点击图像,当它被点击一次
jQuery simple modification to disable click on image when it was clicked once
jQuery简单修改,禁止点击
下面的jQuery使用JqPostForm表单的图像提交按钮来发布。
如何改变图像从image1.png到image3.png时点击和禁用进一步点击?如何在2秒后删除感谢信息?
没有必要保留这个表格。
<script>
$(function(){
$("#JqPostForm").submit(function(e){
e.preventDefault();
$.post("add.php",
function(data){
$("#message_post").html("Thank you");
});
});
$('#submit').hover(
function(){ // Change the input image's source when we "roll on"
$(this).attr({ src : 'image2.png'});
},
function(){ // Change the input image's source back to the default on "roll off"
$(this).attr({ src : 'image1.png'}); }
);
});
</script>
<form id="JqPostForm">
<input type="image" name="submit" id="submit" src="image1.png">
</form>
<div id="message_post"></div>
- 在提交按钮上使用
$(this).unbind('click').attr('disabled', 'disabled');
来禁用它。 -
使用
setTimeout(function () { $("#message_post").hide(); }, 2000);
在2秒后隐藏消息<script> $(function(){ $("#JqPostForm").submit(function(e){ e.preventDefault(); $.post("add.php", function(data){ $("#message_post").html("Thank you"); setTimeout(function () { $("#message_post").hide(); }, 2000); }); }); $('#submit').hover( function(){ // Change the input image's source when we "roll on" $(this).attr({ src : 'image2.png'}); }, function(){ // Change the input image's source back to the default on "roll off" $(this).attr({ src : 'image1.png'}).unbind('click').attr('disabled', 'disabled'); } ); }); </script> <form id="JqPostForm"> <input type="image" name="submit" id="submit" src="image1.png"> </form> <div id="message_post"></div>
我只做了提交表单的一部分:
$("#JqPostForm").submit(function(e){
e.preventDefault();
$.post("add.php",
function(data){
$("#submit").attr('src','image3.png');
$("#submit").attr('disabled',true);
$("#submit").unbind('click');
$("#message_post").html("Thank you");
});
});
我假设您仍然希望它像提交按钮一样运行。我将绑定一个点击处理程序,然后更改图像并禁用输入并取消绑定处理程序:
$('#submit').click(function(e){
$(e.target).unbind('click').attr('src','image3.png').attr('disabled', true);
});
我错过了关于删除感谢信息的部分…您只需要在$中添加一个超时。Post回调,如:
$.post("add.php",
function(data){
$("#message_post").html("Thank you");
setTimeout("$('#mesage_post').html('');", 5000);
});
你可以使用jquery .one()
http://api.jquery.com/one/相关文章:
- Javascript返回值只在循环中返回一次
- Jquery FadeIn FadeOut 只工作一次
- Javascript html每点击一次就会更改url
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- Rails操作只调用一次,但我在ajax中每秒钟都调用一次
- jQuery滚动功能只工作一次
- 刷新导致我的帖子“;张贴“;再一次
- 引导程序崩溃一次只能看到一个
- 有没有一个抽象层,这样我就可以集成一次,然后使用pusher、pubnub或faye
- 加载器组件仅加载一次
- 根据Angular.JS上一次的内容禁用选择
- 一次又一次地在新的和相同的选项卡中打开一个url
- 只在宽度以下和宽度以上各准备一次
- 简单的onclick事件只起过一次作用
- 简单的jQuery将单词的颜色一次查询为蓝色
- 为什么这个简单的.js在一次迭代后循环停止
- 简单模式弹出窗口显示每个会话一次
- 简单嵌套的 setTimeout() 只运行一次 (JavaScript)
- jquery+简单切换脚本+使用不止一次在一个网站上
- jQuery的简单修改,禁用点击图像,当它被点击一次