如何禁用JQuery UI Datepicker字段的手动输入? [英] How to disable manual input for JQuery UI Datepicker field?

查看:65
本文介绍了如何禁用JQuery UI Datepicker字段的手动输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定使用JQuery UI Datepicker脚本来选择日期。以下是我的代码的一部分,我将其整合到我的PHP页面中:

I decided to use the JQuery UI Datepicker script for picking dates. Below is part of my code, and the way I integrated it into my PHP page:

<link type="text/css" href="css/south-street/jquery-ui-1.8.6.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.6.custom.min.js"></script>
<script type="text/javascript">
$(function(){
    // Datepicker
    $('#datepicker').datepicker({ dateFormat: 'yy-mm-dd' });
    //hover states on the static widgets
    $('#dialog_link, ul#icons li').hover(
        function() { $(this).addClass('ui-state-hover'); }, 
        function() { $(this).removeClass('ui-state-hover'); }
    );
});
</script>

And:

    // date picker (embeds JQuery script)
echo '<label for="datepicker">Date: </label>';
echo '<input type="text" name="datepicker" id="datepicker" />';
echo '<div id="datepicker"></div>';

根据JQuery UI说明,很多。

Pretty much according to the JQuery UI instructions.

现在我的问题是:如何在文本输入字段中禁用手动输入?我只希望JQuery Datepicker脚本能够填充文本字段。据我看到,脚本目前阻止用户在文本字段中输入任何非数字字符,但允许使用任何数字组合(因此,允许使用像95460829468这样的乱码。

Now my question is: how can I disable manual inputs in the text input field? I only want the JQuery Datepicker script to be able to fill the text field. As far as I can see, the script currently prevents the user from entering any non-numerical characters into the text field, but any combination of numbers is allowed (therefore, gibberish like "95460829468" is allowed).

推荐答案

输入时,将其设置为只读。

When you make the input, set it to be readonly.

<input type="text" name="datepicker" id="datepicker" readonly="readonly" />

这篇关于如何禁用JQuery UI Datepicker字段的手动输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆