donglu6805 2011-12-15 02:36
浏览 81
已采纳

为什么这个点击处理程序fadeToggle代码不起作用?

I am trying to fade in div elements but for some reason every time I preview my script code it just displays it and doesn't run it

my script code is -

 <script>
$("#t<?php echo $pNumber ?>").click(function() {
$("#b.<?php echo $pNumber ?>").fadeToggle("slow", "linear");
});
</script>

the PHP variable is used for changing div id's would this be causing a problem?

Thanks,

UPDATE -

example html this is for one of the div's (the id is incremented)

  <div id="t1">Carl Froch 'fitter than ever' for Andre Ward Showtime Super Six       fight</div>
  <div id="b1"><p>Carl Froch gives Andre Ward seven years but no encouragement to      believe their fight  on Saturday night is a war of the ages.</p><p>The 34-year-old WBC    champion from Nottingham rarely strays far from the 12-stone limit of his division and is     hard o...<p><a href=http://www.guardian.co.uk/sport/2011/dec/14/carl-froch-andre-  ward-showtime-super-six>Click here for full article</a></p>   </div  <script>
  $("#t1").click(function() {
  $("#b1").fadeToggle("slow", "linear");
  });
 </script>

JB

  • 写回答

1条回答 默认 最新

  • dsfdfd1211 2011-12-15 02:40
    关注

    In your element selectors:

    • You're including the $pNumber as part of the t's id for the click event
    • You're including the $pNumber as part of the b's class for the fadeToggle

    To fix this, do one of these:

    • Add a dot to the #t selector, to make it select based on class
    • Remove the dot from the #b selector, to make it select based on id

    See this fiddle before removing the .:

    $("#t1").click(function() {
        $("#b.1").fadeToggle("slow", "linear");
    });
    

    See this fixed fiddle:

    $("#t1").click(function() {
        $("#b1").fadeToggle("slow", "linear");
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?