如何在第一次单击后禁用日历的单击?[已编辑解决方案]

发布于 2024-12-20 06:29:54 字数 1746 浏览 3 评论 0原文

我在我的应用程序中使用 DHTML 日历。 单击日期后,会执行表单提交操作。

我想在第一次点击后禁用日历,以便用户无法在表单提交之前点击其他日期。

我的代码是

<SCRIPT type="text/javascript">

function dateChanged(calendar) 
{
    // Beware that this function is called even if the end-user only
    // changed the month/year. In order to determine if a date was
    // clicked you can use the dateClicked property of the calendar:
    if (calendar.dateClicked) {
    // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
    var y = calendar.date.getFullYear();
    var m = calendar.date.getMonth() + 1; // integer, 0..11
    var d = calendar.date.getDate(); // integer, 1..31
    var NewDate = y + "-" + m + "-" + d;
    document.getElementById("<?=$mydata[FILTER]?>").value = NewDate;
    submitForm();
}




    var tempDate = new Date(<?=$CalDate?>);
    Calendar.setup({
            flat        : "<?=$mydata[FILTER]?>_show_date",     // ID of the parent element
            flatCallback:dateChanged,                                           // our callback function
            weekNumbers:false,                                              // Don't display week numbers
            date        : tempDate      
                    // Set calendar to start at selected date
        });

    document.getElementById("<?=$mydata[FILTER]?>").value = '<?=$mydata[FILTER]?>';

我为此做了一个解决方案 我禁用了 div 和 div 的所有子元素 使用代码

**var nodes = document.getElementById("13-1_show_date").getElementsByTagName('*');
for(var i = 0; i < nodes.length; i++)
{                                               
nodes[i].disabled = true;
}     
submitForm();**

此代码将在第一次单击后禁用 div 及其子级。

i am using an DHTML calendar in my application.
on clicking a date ,there is a form submit action.

i want to disable the calendar after first click ,so that user can not click the other date before the form submit.

my code is

<SCRIPT type="text/javascript">

function dateChanged(calendar) 
{
    // Beware that this function is called even if the end-user only
    // changed the month/year. In order to determine if a date was
    // clicked you can use the dateClicked property of the calendar:
    if (calendar.dateClicked) {
    // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
    var y = calendar.date.getFullYear();
    var m = calendar.date.getMonth() + 1; // integer, 0..11
    var d = calendar.date.getDate(); // integer, 1..31
    var NewDate = y + "-" + m + "-" + d;
    document.getElementById("<?=$mydata[FILTER]?>").value = NewDate;
    submitForm();
}




    var tempDate = new Date(<?=$CalDate?>);
    Calendar.setup({
            flat        : "<?=$mydata[FILTER]?>_show_date",     // ID of the parent element
            flatCallback:dateChanged,                                           // our callback function
            weekNumbers:false,                                              // Don't display week numbers
            date        : tempDate      
                    // Set calendar to start at selected date
        });

    document.getElementById("<?=$mydata[FILTER]?>").value = '<?=$mydata[FILTER]?>';

i made a solution for this
i disabled div and all the children of div
using the code

**var nodes = document.getElementById("13-1_show_date").getElementsByTagName('*');
for(var i = 0; i < nodes.length; i++)
{                                               
nodes[i].disabled = true;
}     
submitForm();**

this code will disable the div and its childrens after first click.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放赐 2024-12-27 06:29:54

这个问题是一个经典问题,解决方法有很多种:

  1. 使用一个名为isClciked的临时变量,并在第一次点击时将其设置为true,在后续点击中检查它,如果为true,则只需返回;
  2. 第一次执行点击处理程序时,禁用整个日历(这本身有很多方法)

This problem is a classical problem, and there are many ways:

  1. Use a temporary variable called isClciked and set it to true in the first click, and in subsequent clicks, check it, and if it's true, then simply return;.
  2. On the first execution of your click handler, disable the entire calender (this in itself has many ways)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文