我需要在jQuery中替换document.createElement,有什么办法吗?
for (let word in myDictionary) {
let buttonElement = document.createElement('button');
$(buttonElement).html(word);
$(buttonElement).on("click", createOnClickListener(myDictionary[word]));
let listItemElement = document.createElement("li");
$(listItemElement).append(buttonElement);
$(buttonListElement).append(listItemElement);
}
答案 0 :(得分:4)
$('<tagname>')
创建包裹在jQuery对象中的元素
let $button = $('<button>').html(word).on('click', createOnClickListener(myDictionary[word]));
let $listItem = $('<li>').append($button);