jquery - client-side disabling manual input in p:spinner not working
问题描述
I am using PrimeFaces <p:spinner>
, I want to disable manual input, by setting the <input>
tag of the spinner to readonly. I have tried to achieve it by using jQuery:
$('.ui-spinner-input').prop('readonly', true);
$('#dtProduct:spinnerQty').prop('readonly', true);
$('#dtProduct:spinnerQty_input').prop('readonly', true);
Non of the above works. I have also try to select it by tag name and loop through it:
$("input").each(function()
{
alert("");
if($(this).hasClass("ui-spinner-input")) {
alert("");
}
});
doesn't work neither, not even alert anything. I am sure that my jQuery is working by using this technique.
Below is the screenshot of the element source code from Google Chrome
My class name and id looks right, but it just not working at all, any idea?
解决方案
它适用于以下代码:
$(document).ready(function() {
disableInput();
});
function disableInput()
{
$('.ui-spinner-input').bind("keydown", function(event) {
event.preventDefault();
});
$('.ui-spinner-input').focus(function() {
$(this).blur();
});
}
$(document).ready(function() {});
是原因。在所有 DOM 准备好后,将加载此主体中的函数。
推荐阅读
- java - 如何在 Android Studio 中正确创建从 AAR 导入的 Android 库模块?
- openssl - 禁用 TLS 1.0 成为 PCI 投诉
- python-2.7 - 从许多文件中保存特定数据
- r - 在 clusterApply 中的块之间传递外部值(并行包)
- c - 指向多维数组错误的指针:表达式必须具有指向对象的指针类型
- netsuite - Netsuite 中的条件必填字段
- amazon-kinesis - KCL 如何在内部产生新的 RecordProcessor
- r - 如何从滑块输入中获取值并将它们写入变量?
- mysql - 在 mysql 中管理版本化数据
- apache-spark - 火花流作业中任务之间的长时间且一致的等待