$('< div />')做什么? [英] what does $('<div/>') do?

查看:109
本文介绍了$('< div />')做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工具提示脚本中的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元素。
$ b


当参数有一个标签时,比如 $('< div />')
$('< a>< / a>'),jQuery使用原生JavaScript $ b $创建元素b createElement()函数。

结果如下所示:

  $(document.createElement(div)); 

详情请参阅 这里


I saw this in jQuery tools in the tooltip script. What is <div/> ? I've never seen the backslash used that way. Probably going to get some down votes, but I must know.

解决方案

It used to create a div element. Its short cut to <div></div>.

For example:

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

will create div with id: hello, class: new with html New div and append to #target.

DEMO

More details

It means "create a jQuery-wrapped div element on the fly".

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

As result it will look like:

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

For detail see here

这篇关于$('&lt; div /&gt;')做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆