从文本链接触发的JQuery UI datepicker [英] JQuery UI datepicker triggered from text link

查看:59
本文介绍了从文本链接触发的JQuery UI datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置我的css菜单,以便其中一个文本链接触发datepicker calandar打开。我已将所有内容删除至下面的代码。我遇到的问题是下面的代码不起作用,但当我删除ul,li标签时它开始工作。

I'm trying to setup my css menu so that one of the text links triggers a datepicker calandar to open. I have stripped everything down to the code below. The problem I am experiencing is that the code below does not work but when I remove the ul, li tags it starts working.

我使用的是1.8.0 JQuery和1.8 .23 JQuery UI。

I am using 1.8.0 JQuery and 1.8.23 JQuery UI.

<!DOCTYPE html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("#dp").datepicker({
        onSelect: function(dateText, inst) {
            alert(dateText);
        },
    });

    $("#datep").click(function() {
        $("#dp").datepicker("show");
    });
});
</script>
</head>
<body>
<ul>
    <li><a href="#" id="datep">Test</a><input type="hidden" id="dp" /></li>
</ul>
</body>
</html>

我注意到一些奇怪的事情。如果我在ul下移动输入它会起作用,但是在点击几下后会出现错误,但是如果我在该输入下添加空div,那么它将开始正常工作。

Some weird things I have noticed. If I move the input under the ul it works kind of but will get an error after a few clicks on and off but if I add empty div under that input then it will start working normally it seems.

非常感谢任何帮助。

推荐答案

所以这是一个错误。您必须在隐藏输入后立即添加块级元素:

So this is a bug. You'll have to add a block-level element right after the hidden input:

HTML:

<ul>
    <li><a href="#" id="datep">Test</a>
        <input type="hidden" id="dp" />
        <div></div>
    </li>
</ul>​

示例: http://jsfiddle.net/andrewwhitaker/LE2CG/1/

这篇关于从文本链接触发的JQuery UI datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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