-1

クラスを与えることでこれをスタイルできないのはなぜですか

<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);});
4

2 に答える 2

3

クラス名を二重引用符で囲んで、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/

于 2012-11-10T00:37:26.573 に答える
0
$("<div class=\"ko\">add image</div>")
于 2012-11-10T00:41:14.567 に答える