gpt4 book ai didi

jquery - $ ('
' ) 是做什么的?

转载 作者:太空狗 更新时间:2023-10-29 14:02:12 25 4
gpt4 key购买 nike

我在工具提示脚本的 jQuery 工具中看到了这一点。什么是 <div/> ?我从未见过以这种方式使用反斜杠。可能会得到一些反对票,但我必须知道。

最佳答案

它曾经创建一个 div元素。它的捷径是<div></div> .

例如:

$('<div/>', {id: 'hello', 'class': 'new', html: 'New div'}).appendTo('#target');

将使用 id: hello 创建 div , class: new用 html New div并附加到 #target .

DEMO

更多详情

意思是“动态创建一个 jQuery 包装的 div 元素”。

When the parameter has a single tag, such as $('<div />') or$('<a></a>'), jQuery creates the element using the native JavaScriptcreateElement() function.

结果看起来像:

$(document.createElement("div"));

详情见 here

关于jquery - $ ('<div/>' ) 是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10970705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com