簡體   English   中英

使用 jQuery 在 wordpress 上使更多的整個 div 可點擊

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

總結問題

我 state 我對 html 和 javascript 語言幾乎一無所知,我知道 ZC7A628CBA22E2A28EB17B5F5C66 在 wordpress 上,使用可視化作曲家,我試圖使整行可點擊。 我已經使用在線創建的 jQuery 代碼完成了它:

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

我已將 java 的 object 添加到可視化作曲家中,並輸入了代碼。 創建類后,插入鏈接,將“光標:指針”function 添加到 CSS,一切正常。

問題是它只能在單行上工作。 當我嘗試復制代碼、分配不同的類和鏈接以創建更多可點擊的 div 時,它不起作用。 結果是只有頁面的第一個 div 是可點擊的,div 不是。

我試過的

我以不同的組合嘗試了以下代碼:

<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>

始終將 object 用於 java 代碼:我將它們放在一起,分別放在我想要使其可點擊的行中,它不起作用。 結果總是一樣的:只有第一個 div 變得可點擊。 即使將 java 代碼的 object 從第一行移到其他行,結果也是一樣的。 第一個 div 始終是唯一可點擊的。

為了確保你的js jquery 代碼有效,通過a.js 文件添加腳本

但首先,查找主題的 footer.php 文件並添加以下代碼:

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

在 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>

請記住,您必須將 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>

我找到了解決方案。 通過導入上面編寫的代碼,如您所糾正,它可以工作。 我不知道這種方法在理論上是否正確,但它工作正常。 所以...

在可視化作曲家中,您必須插入 object 以在要使其可點擊的每一行中添加 java 代碼(例如:對於 5 個可點擊的 div,您制作 5 個對象以插入 Z93F725A07423D1C8836F 代碼) 在每個 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