在这一特定场景中,数据被覆盖

Data being overwritten in this one specific scenario

本文关键字:数据 覆盖      更新时间:2023-09-26

我是JS和HTML的新手,有很多东西我正在努力理解,所以如果有人能帮忙解释,那就太好了。

这是我的片段。

<script>
$(".radio-inline").click(function(){
 $("#team").click(function(){
    create_Countdown(data[2].year, data[2].month, data[2].day, data[2].Hours, data[2].ampm, data[2].minute, data[2].second); 
   });
});
</script>

出于某种原因,每当我在jquery函数中调用create_Countdown()函数时,它都是在一个全空白的页面上生成的。我认为所有其他代码都是由于某种原因而被删除的。奇怪的是,如果我在不调用jquery函数的情况下调用该函数,它会打印到我想要的地方

有人能帮忙吗?

对于那些要求在此处查看create_Countdown()代码的人来说,它是

function create_Countdown(yearx, monthx, dayx, hourx, ampmx, minutex, secondx){ //Code to create a new countdown with the parameters
    new Countdown({year  : yearx, 
    month : monthx, 
    day   : dayx, 
    hour  : hourx,
    ampm  : ampmx,
    minute  : minutex, 
    second  : secondx});

}

我试着把回报放在新的之前,看看是否会有不同,但没有。

为什么点击处理程序相互嵌套?

$(".radio-inline").click(function(){
   // when I click .radio-inline
   // then attach click handler to #team element
   $("#team").click(function(){
      //then when I click #team , after I have click radio-inline
      //then create count_countdown
        create_Countdown(data[2].year, data[2].month, data[2].day, data[2].Hours, data[2].ampm, data[2].minute, data[2].second); 
   });
});

我通过查看他们的"高级选项"示例了解到了这一点。基本上,您需要指定一个创建Countdown的目标(否则,它似乎使用document.write或其他会扰乱html的东西)。

首先,你需要这个在你的html:的某个地方

<div id="countdown"></div>

然后,在您的javascript:中

function create_Countdown(yearx, monthx, dayx, hourx, ampmx, minutex, secondx) {
    new Countdown({
        year   : yearx, 
        month  : monthx, 
        day    : dayx, 
        hour   : hourx,
        ampm   : ampmx,
        minute : minutex, 
        second : secondx,
        target : "countdown" // A reference to an html DIV id
    });
}

这个命令告诉Countdown在现有的HTML元素中创建自己,而不是它的默认行为。

你可以在这里看到它的作用:http://jsfiddle.net/gnhtb1cp/5/