簡體   English   中英

嘗試追加元素后,jQuery停止執行

[英]jquery stops execution after trying to append element

我的函數應該復制兩次元素內部,然后追加它們,但是由於某種原因,jQuery在第一次追加之后停止執行。 我不理解為什么。

$(".testowyUl").prepend(function () {
  var $temp = $(this).children().clone();
  var $temp2 = document.createElement("div");
  $temp2.append($temp);
  $temp2.append($(this).children().clone());
  return $temp2.children();
});

嘗試:

var $temp2 = $("<div>");

代替:

var $temp2 = document.createElement("div");

創建一個jQuery對象。 由於DOM元素中沒有“附加”方法。

您在非Jquery對象上調用append

$temp2.append($temp);

導致

Object #<HTMLDivElement> has no method 'append'

更新:

你可以嘗試使用

var $temp2 = $("div");

代替

var $temp2 = document.createElement("div");

在這里看到一個工作的小提琴

暫無
暫無

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

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