Jquery 可点击块指针

Jquery 可点击块指针,jquery,css,pointers,cursor,clickable,Jquery,Css,Pointers,Cursor,Clickable,容器可单击,但光标保持不变。css选择器为什么不工作?的返回值from.attr是属性值,而不是jquery对象 // clickable blocks $(".product").click( function () { window.location = $(this).find('a').attr("href").css("cursor", "pointer"); return false; }); 如果您希望容器有一个新光标,那么您可能需要: $(".product")

容器可单击,但光标保持不变。css选择器为什么不工作?

的返回值from.attr是属性值,而不是jquery对象

// clickable blocks
$(".product").click(
function () {
    window.location = $(this).find('a').attr("href").css("cursor", "pointer");
    return false;
});
如果您希望容器有一个新光标,那么您可能需要:

$(".product").click(function () {
  window.location = $(this).find('a').attr("href");
  $(this).find('a').css("cursor", "pointer");
  return false;
});

.attr的返回值是属性值,而不是jquery对象

// clickable blocks
$(".product").click(
function () {
    window.location = $(this).find('a').attr("href").css("cursor", "pointer");
    return false;
});
如果您希望容器有一个新光标,那么您可能需要:

$(".product").click(function () {
  window.location = $(this).find('a').attr("href");
  $(this).find('a').css("cursor", "pointer");
  return false;
});

是否确实要在单击块中设置光标?在我看来,要做你真正想做的事,你需要这样做:

编辑:确定,考虑到您只希望在包含a的事件上设置单击事件:

$(".product").click(function () {
  window.location = $(this).find('a').attr("href");
  $(this).css("cursor", "pointer");
  return false;
});

是否确实要在单击块中设置光标?在我看来,要做你真正想做的事,你需要这样做:

编辑:确定,考虑到您只希望在包含a的事件上设置单击事件:

$(".product").click(function () {
  window.location = $(this).find('a').attr("href");
  $(this).css("cursor", "pointer");
  return false;
});
查找所有具有链接的产品 将指针作为光标 处理单击事件以更改位置 守则:

$(function() { // or $(document).ready(function() {
    $(".product").each(function() {
        if ($(this).has('a')) {
            $(this).css("cursor", "pointer");
            $(this).click(
            function () {
                window.location = $(this).find('a').attr("href");
                return false;
            });
        }
    });
});
查找所有具有链接的产品 将指针作为光标 处理单击事件以更改位置 守则:

$(function() { // or $(document).ready(function() {
    $(".product").each(function() {
        if ($(this).has('a')) {
            $(this).css("cursor", "pointer");
            $(this).click(
            function () {
                window.location = $(this).find('a').attr("href");
                return false;
            });
        }
    });
});

我想它会添加指向所有.产品块的指针?我也可以通过css实现这一点,但只有链接的才会有。@Nimbuz:此编辑版本可能更符合您的要求。$.product:hasa[href]应该为您提供带有链接的产品。我猜它会添加指向所有.product块的指针?我也可以通过css实现这一点,但只有链接的才应该有。@Nimbuz:这个编辑版本可能更符合您的要求。$.product:hasa[href]应该为您提供带有链接的产品,因为它只在单击时才有光标。那是因为它只在单击时才有光标。啊,我忘了除了.has函数之外还有一个:has选择器。哎呀。jQuery站点搜索没有为hasAh返回任何结果,这没有帮助,我忘记了除了.has函数之外还有一个:has选择器。哎呀。jQuery站点搜索没有为has返回任何内容,这没有帮助