Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery-.on(';单击';)不处理<;李>;_Javascript_Jquery - Fatal编程技术网

Javascript jQuery-.on(';单击';)不处理<;李>;

Javascript jQuery-.on(';单击';)不处理<;李>;,javascript,jquery,Javascript,Jquery,所以我的任务是用Wordpress制作一个网站,在主页上有一个滑块,如果你点击下面的按钮,它会显示另一个图像,很简单吧?嗯,我有滑块和按钮,我添加了jQuery,但它不想工作 我第一次尝试制作按钮,实际上是按钮: <button type="button" class="btn btn-success" id="hideshow-healthcare">Healthcare</button> 因此,在它像那样工作之后,我转而在李家做按钮,这样我就可以按照设计。执行此操作

所以我的任务是用Wordpress制作一个网站,在主页上有一个滑块,如果你点击下面的按钮,它会显示另一个图像,很简单吧?嗯,我有滑块和按钮,我添加了jQuery,但它不想工作

我第一次尝试制作按钮,实际上是按钮:

<button type="button" class="btn btn-success" id="hideshow-healthcare">Healthcare</button>
因此,在它像那样工作之后,我转而在李家做按钮,这样我就可以按照设计。执行此操作后,滑块将不再工作。我尝试了多种不同的方法,包括在li中的所有内容中添加ID,以查看这是否有效,但遗憾的是没有。我做了一些研究,试图改变

    jQuery('#hideshow-healthcare').on('click', function() {

但还是没有运气。我希望有人能为这个问题提供解决方案

此外,这是我目前使用的li代码:

<li><a id="hideshow-healthcare"><h5>HEALTHCARE</h5> Lighting to create a feeling of well being</a></li>
  • 医疗照明创造幸福感

  • 您需要在li元素后添加空格以查找其子元素
    #hideshow healthcare
    。应该是

     jQuery('li #hideshow-healthcare').on('click', function() {
    
    #hideshow healthcare
    是李的孩子
    。在jquery中使用子体选择器

    jQuery('li a#hideshow-healthcare').on('click', function(event) {
           event.preventDefault(); // prevents default action 
           // your code 
    });
    
    Id在html中是唯一的您只需直接使用Id编写即可

    jQuery('#hideshow-healthcare').on('click', function(event) {
               event.preventDefault(); // prevents default action 
               // your code 
     });
    

    非常感谢。它起作用了。。。我现在觉得自己很傻,很简单的事情哈哈哈。一旦我有能力,我会把你的答案标记为正确答案@穆塞凡:我正要提到这一点。但我想如果OP需要它,为什么不…@JoshJohnsonUK:很高兴它能帮上忙:)是的,他似乎对它很满意。。。但这仍然会将事件添加到
    a
    标记中,对吗?我想也许OP没有意识到你想做什么?你的第一次工作尝试与你声称对你有用的答案没有什么不同。。。你没有得到任何不同的结果。我想知道这是否是因为您没有使用
    e.preventDefault()在单击事件中?实际上,您没有
    href
    ,因此问题不需要防止默认。我不太确定在第一次尝试之间发生了什么变化,因为我能看到的唯一不同之处是li和ID之间的空间,但它似乎在工作:/
    jQuery('li a#hideshow-healthcare').on('click', function(event) {
           event.preventDefault(); // prevents default action 
           // your code 
    });
    
    jQuery('#hideshow-healthcare').on('click', function(event) {
               event.preventDefault(); // prevents default action 
               // your code 
     });