2011-12-09 46 views
1

我在我的应用程序中使用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 的所有儿童

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

此代码将禁用解决方案第一次点击后div和它的孩子。

回答

1

这个问题是一个经典的问题,有很多方法:

  1. 使用名为isClciked一个临时变量,并将其设置为true,第一次点击,并在随后的点击,检查它,如果它是真的,那么只需return;
  2. 在您单击处理程序的第一次执行,禁用整个压延机(这本身就具有很多方面)
+0

我们可以做到这一点。 但问题是它应该是可见的用户日历已禁用,无法再单击,直到表单提交。 –

+0

然后只需使用CSS即可。 –

+0

请问你能更清楚吗? 使用CSS,我们如何阻止点击 我不想隐藏日历。 –

相关问题