doucheng1884 2013-12-27 04:00
浏览 20
已采纳

点击内部仅在标签内点击两次()

I have a container on my page called task1 containing a slideshow, back button and next button. The final page will have task1 as one of a series of tabs(container called tasks). My onClick event works perfectly when I leave out the tabs() function. As soon as I add the tabs(), the onClick fires twice. I have checked other questions, but the most popular answer of "check if the code is written twice" does not hold any water.

Any suggestions? Thanks in advance.

HTML:

<div class="content" id="tasks">
  <ul>
    <li><a href="#task1">Review for Quiz</a></li>
    <li><a href="#task2">task 2</a></li>
    <li><a href="#task3">task 3</a></li>
    <li><a href="#task4">task 4</a></li>
    <li><a href="#task5">Blackjack</a></li>
  </ul>                 

  <div class="content" id="task1"></div>
  <div class="content" id="task2"></div>
  <div class="content" id="task3"></div>
  <div class="content" id="task4"></div>
  <div class="content" id="task5"></div>
</div>

jquery:

$("#tasks").tabs();

$(".content").on('click','.yNext',function(){
    $.ajax({
        url: "task1php.php",
        async: true,
        type: "POST",
        data: {func: 3}
    }).success(function(data){
        alert(data);
        $("#task1").html(data);
    });
});

php to generate slides(.yNext is the next button and .yBack is back button):

if($slide == '55')
$slide = '1';
else
    $slide++;   
echo "<div class='yLeftSs'>";
echo "<input class='yBack' type='image' src='images/BackArrow.png' />";//back button
echo "</div>";
echo "<div class='yCenterSs'>";
echo "<img class='ySlides' src='images/Task1_slides/Slide".$slide.".PNG'/>";
echo "</div>";
echo "<div class='yRightSs'>";
echo "<input class='yNext' type='image' src='images/NextArrow.png' />";//next button
echo "</div>";  
  • 写回答

1条回答 默认 最新

  • dqxboe2628 2013-12-27 04:26
    关注

    Add return false; to the end of the click handler to prevent the default action and event bubbling. One of these seems to be triggering the handler again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法