简体   繁体   English

使用 jQuery 在 wordpress 上使更多的整个 div 可点击

[英]make more entire div clickable on wordpress using jQuery

SUMMARIZE THE PROBLEM总结问题

I state that I know practically nothing about html and javascript languages, I know the css.我 state 我对 html 和 javascript 语言几乎一无所知,我知道 ZC7A628CBA22E2A28EB17B5F5C66 On wordpress, with visual composer, i was trying to make an entire row clickable.在 wordpress 上,使用可视化作曲家,我试图使整行可点击。 I've done it using a jQuery code founded online:我已经使用在线创建的 jQuery 代码完成了它:

<script type="text/javascript"> 
jQuery(".LinkZoom1").click(function() {
    window.location = "http://www.framedvision.org/portfolio/videomapping_oggetti_milano/";
});
</script>

I've added to the visual composer the object for java and I've put in the code.我已将 java 的 object 添加到可视化作曲家中,并输入了代码。 After I created the classes, inserted the link, added to the CSS the "cursor: pointer" function and everything works correctly.创建类后,插入链接,将“光标:指针”function 添加到 CSS,一切正常。

THE PROBLEM IS THAT IT WORKS ONLY ON A SINGLE ROW.问题是它只能在单行上工作。 When I try to duplicate the code, assign different classes and links to create more clickable divs, it doesn't work.当我尝试复制代码、分配不同的类和链接以创建更多可点击的 div 时,它不起作用。 The result is that only the first div of the page is clickable, the divs are not.结果是只有页面的第一个 div 是可点击的,div 不是。

WHAT I'VE TRIED我试过的

I tried the following codes in different combinations:我以不同的组合尝试了以下代码:

<script type="text/javascript"> 
jQuery(".class1”).click(function() {
    window.location = “#1”;
}); 
</script>

<script type="text/javascript"> 
jQuery(".class2”).click(function() {
    window.location = “#2”;
}); 
</script>

<script type="text/javascript"> 
jQuery(".class3”).click(function() {
    window.location = “#3”;
}); 
</script>

<script type="text/javascript"> 
jQuery(".class4”).click(function() {
    window.location = “#4”;
}); 
</script>

<script type="text/javascript"> 
jQuery(".class5”).click(function() {
    window.location = “#5”;
}); 
</script>

Always using the object for java code: I put them all together, put individually in the row that I want to make clickable, it doesn't work.始终将 object 用于 java 代码:我将它们放在一起,分别放在我想要使其可点击的行中,它不起作用。 The result is always the same: only the first div becomes clickable.结果总是一样的:只有第一个 div 变得可点击。 Even moving the object for java code away, from the first row to other rows, the result is the same.即使将 java 代码的 object 从第一行移到其他行,结果也是一样的。 The first div is always the only clickable.第一个 div 始终是唯一可点击的。

To make sure your js jquery code is valid, add a script through a.js file为了确保你的js jquery 代码有效,通过a.js 文件添加脚本

But first of all, look for your theme's footer.php file and add the code below:但首先,查找主题的 footer.php 文件并添加以下代码:

jQuery(document).ready(function(){
    jQuery(".your_class").click(function() {
        window.location = "https://bluebezer.com.br";
    }); 
});

right after wp_footer ();在 wp_footer () 之后;

        <?php wp_footer(); ?> 

        <!-- add here the sample code -->

        jQuery(document).ready(function(){
            jQuery(".your_class").click(function() {
                window.location = "https://bluebezer.com.br";
            }); 
        });

    </body>
</html>

Remember that you must put the class in the elements you want it to be clickable and the elements must have the class you used in the javascript code exactly as you wrote it.请记住,您必须将 class 放入您希望它可点击的元素中,并且元素必须具有您在 javascript 代码中使用的 class 与您编写的完全相同。

<div class="your_class"> <!-- this will execute the clickable code -->
    <!-- ... other code -->
</div>


<div class="your_class35413"> <!-- this will not execute the clickable code -->
    <!-- ... other code -->
</div>

<div class="your_class"> <!-- this will execute the clickable code -->
    <!-- ... other code -->
</div>

<div class="your_class4156130"> <!-- this will not execute the clickable code -->
    <!-- ... other code -->
</div>

<div class="your_class"> <!-- this will execute the clickable code -->
    <!-- ... other code -->
</div>

I found the solution.我找到了解决方案。 By importing the code written above, as corrected by you, it works.通过导入上面编写的代码,如您所纠正,它可以工作。 I don't know if this method is theorically correct, but it works fine.我不知道这种方法在理论上是否正确,但它工作正常。 So...所以...

In the visual composer, you have to insert an object to add the java code in each row that you want to make clickable (for example: for 5 clickable divs, you make 5 objects to insert the java code).在可视化作曲家中,您必须插入 object 以在要使其可点击的每一行中添加 java 代码(例如:对于 5 个可点击的 div,您制作 5 个对象以插入 Z93F725A07423D1C8836F 代码) Inside each object you have to insert the specific code for each class:在每个 object 中,您必须为每个 class 插入特定代码:

<script type="text/javascript">
jQuery(".class1”).click(function() {
window.location = “#1”;
});
</script>    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM