簡體   English   中英

使 <div> , <li> 無<a>標簽</a>可點擊

[英]Make <div>, <li> clickable without <a> tag

我希望<div><li>標簽可以點擊(指針應該變為手)。 沒有<a>標簽我該怎么辦?

因為,當點擊div時,我的javascript會加載一個文本文件。

您應該為手形指針添加style="cursor:pointer" ,並且onclick="window.location='somewhere'"

<div style="cursor:pointer" onclick="window.location='index.html'">My Link</div>
var myel = document.querySelector('#myel'); // your element

myel.addEventListener('click', function() {
  // do stuff
});

在CSS中:

#myel { cursor: pointer }

你可以通過多種方式做到這一點。 一種方法是在你的CSS中分配偽類。 如果div有一個div1類,那么我們的css會讀:

.div1:hover{
    cursor:pointer;
}

你也可以用javascript來做

$('.div1').on("hover", function(){
    $(this).css("cursor", "pointer");
});

設置CSS:

ul li{
  cursor:pointer; /*  <------this will change the cursor to hand cursor*/
}

和jQuery:

$(function(){
   $('li').click(function(){
      alert('li clicked.');
   });
});
        $("div").hover(function(){
        $(this).css('cursor','pointer')
});

希望這可以幫助...

CSS

li:hover {
    cursor: pointer //on hover change the cursor to pointer
}

JQuery的

$(document).ready(function() { 
    $("#click_me").bind("click", function(){ //bind a click event on an element with id = click_me
        $.ajax({ 
            url: "./file.txt", //note: file must be in the same domain as the current script http://en.wikipedia.org/wiki/Same_origin_policy
            dataType: "text",
            success: function(data) { //if ajax request is successful
                $("#result_container").html(data); //append the resulting data into a div with id = result_container
        }
    });
});

});

干杯:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM