如何在 jQuery 中创建 div
元素?
最佳答案
从 jQuery 1.4 开始,您可以将属性传递给自闭合元素,如下所示:
jQuery('<div>', {
id: 'some-id',
class: 'some-class some-other-class',
title: 'now this div has a title!'
}).appendTo('#mySelector');
它在 Docs
示例可以在 jQuery 1.4 Released: The 15 New Features you Must Know 找到.
关于javascript - 在 jQuery 中创建一个 div 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/867916/