$('< div />')做什么? [英] what does $('<div/>') do?
问题描述
我在工具提示脚本中的jQuery工具中看到了这一点。什么是< div />
?我从来没有见过使用这种方式的反斜杠。可能会得到一些倒票,但我必须知道。
它用于创建 div
元素。它的缩写为< div>< / div>
。
$ b $
$('< div />',{id:'hello','class':'new',html:'New div '})appendTo(' #靶');
将创建包含 id:hello
的div, class:new
with html 新div
并附加到 #target
。
DEMO 它意味着即时创建一个jQuery包装的div元素。 当参数有一个标签时,比如 结果如下所示: 详情请参阅 这里 I saw this in jQuery tools in the tooltip script. What is It used to create a For example: will create div with It means "create a jQuery-wrapped div element on the fly". When the parameter has a single tag, such as As result it will look like: For detail see here 这篇关于$('< div />')做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多详细信息
$ b
$('< div />')
或
$('< a>< / a>')
,jQuery使用原生JavaScript $ b $创建元素b createElement()
函数。
$(document.createElement(div));
<div/>
? I've never seen the backslash used that way. Probably going to get some down votes, but I must know.div
element. Its short cut to <div></div>
.$('<div/>', {id: 'hello', 'class': 'new', html: 'New div'}).appendTo('#target');
id: hello
, class: new
with html New div
and append to #target
.More details
$('<div />')
or
$('<a></a>')
, jQuery creates the element using the native JavaScript
createElement()
function.$(document.createElement("div"));