【问题标题】:styling jquery div in css在 css 中设置 jquery div 样式
【发布时间】:2012-10-30 08:37:44
【问题描述】:

为什么我不能通过上课来设置样式

<div class="ko">add image</div>

http://jsfiddle.net/6MmMe/27/

$("div").hover(
  function () {
    $("<div class="ko">add image</div>").click(function() {
        $(this).parent().unbind("hover").children("img").attr("src", "http://www.onlinegrocerystore.co.uk/images/goodfood.jpg");
        $(this).remove();
    }).appendTo(this);
  }, 
  function () {
    $(this).find("div:last").remove();
  }
);



//li with fade class
    //$("li.fade").hover(function(){$(this).fadeOut(100);$(this).fadeIn(500);});

【问题讨论】:

  • 天啊,乱码。 =/
  • 我将鼠标悬停在 img 标签上不起作用 jsfiddle.net/6MmMe/31 是什么原因
  • 图片是空的,你不能附加到它们上面。

标签: jquery-ui jquery jquery-plugins jquery-selectors


【解决方案1】:

您已经通过将类名括在双引号中来关闭用于创建 div 的字符串。使用单引号(双引号内)来阻止这种情况的发生......

$("div").hover(
    function () {
        $("<div class='ko'>add image</div>").click(function() {
            $(this).parent().unbind("hover").children("img").attr("src", "http://www.onlinegrocerystore.co.uk/images/goodfood.jpg");
            $(this).remove();
        }).appendTo(this);
    }, 
    function () {
        $(this).find("div:last").remove();
    }
);

查看此更新小提琴...

http://jsfiddle.net/6MmMe/28/

【讨论】:

【解决方案2】:
$("<div class=\"ko\">add image</div>")

【讨论】:

  • 我将鼠标悬停在 img 标签上不起作用 jsfiddle.net/6MmMe/31 是什么原因
  • 我猜你不能附加到“img”标签,使用像 div 这样的容器来实现你的功能。试试这个jsfiddle.net/6MmMe/35
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-25
  • 2019-11-23
  • 1970-01-01
  • 1970-01-01
  • 2016-04-18
相关资源
最近更新 更多