使输入文本不可编辑,然后使用jQuery在3秒内使其再次可编辑
Making input text uneditable before making it editable again in 3 seconds using jQuery
我有一个输入文本,当你按回车键时,它应该使输入文本不可编辑,然后在3秒内再次可编辑。但由于某种原因,它不起作用。我做错了什么?谢谢。
<input type = "text" id = "text">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type = "text/javascript">
$(function(){
$("#text").keyup(function(e){
if (e.which == 13) {
$("#text").prop("readonly", true);
setTimeout(function(){
$("#text").prop("readonly", false);
}, 3000);
}); //end of if (e.which == 13)
}); //end of $(function())
</script>
结尾有一个简单的拼写错误,有一个额外的括号,删除它
$(function() {
$("#text").keyup(function(e) {
if (e.which == 13) {
$("#text").prop("readonly", true);
setTimeout(function() {
$("#text").prop("readonly", false);
}, 3000);
} //end of if (e.which == 13)
//-^--- remove ) from here
}); //end of $(function())
});
// also add this closing
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" id="text">
根据你的jquery版本的不同可以使用:
$("#text").attr('readonly', true); //this work for older jquery version
或
$("#text").prop('readonly', true); //for new jquery version
删除只读属性,可以使用removeAttr()
$("#text").removeAttr('readonly');
相关文章:
- CKEditor Widget-阻止编辑可编辑元素本身
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 显示5秒后隐藏潜水
- 高亮显示时编辑文本大小和颜色
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 将事件聚焦/模糊在可编辑内容的元素上
- 编辑HTML表的源数据
- X秒后刷新select元素
- ExtJS网格单元格编辑器,防止焦点松动问题
- 如何在visualstudio中调试web api时编辑javascript文件
- 具有所有样式的文本正在复制到可编辑文本区域
- 可以't使用PHP使用Froala编辑器上传图像URL
- 用Greasemonkey编辑专栏
- 如何在corona sdk中从CK编辑器中检索数据
- 基于数据类型的编辑框的汇总列表
- 如何使用jQuery可编辑插件检查ajax是否成功完成
- 如何每10.6秒从时间戳增加+1
- 使输入文本不可编辑,然后使用jQuery在3秒内使其再次可编辑
- 使用Javascript使输入框在用户输入后的3秒内可编辑
- 编辑此工具提示实现,使工具提示等待x秒隐藏