-我正在学习Jquery。我不明白在这个代码这个$('<td/>')
选择:Jquery选择器<td/>
$('<td/>').insertAfter($(this)).text(height).css('border', 'thin solid red');
- 可以任何一个告诉我是什么呢?
-我正在学习Jquery。我不明白在这个代码这个$('<td/>')
选择:Jquery选择器<td/>
$('<td/>').insertAfter($(this)).text(height).css('border', 'thin solid red');
- 可以任何一个告诉我是什么呢?
$('<td/>')
创建一个带有标记td
的DOM元素。
insertAfter($(this))
在this
元素后附加元素。
.text(height)
更改td
标记内的文本。
最后,.css('border', 'thin solid red');
将红色边框应用于td
元素。
$('<td/>')
创建一个新的空白<td>
元素并将其包装在jQuery对象中。
这将是相同的,就像您创建了纯JavaScript的元素,然后使用$('.selector')
进行选择。
让我们打破这种分解成各个组成部分,也许这将是更有益的:
$('<td/>') // this is initializing a new DOM Node. At this point, however, it's not actually connected to anything, it's just a DOM Node hanging out in the DOM and not attached to the document flow.
.insertAfter($(this)) // now, this is telling jQuery to take that TD element you just created, and insert it after whatever $(this) evaluates to... assuming this is inside, say, a click handler, it would evaluate to the object that triggered the click event, and attach the TD element after "this" element.
.text(height) // says, "set the .text of your TD element to whatever is in the height variable" ... you're basically plugging text inside your TD element.
.css('border', 'thin solid red') // is telling jQuery to modify the TD's style, adding a style for border that is thin, solid and red.
见我一起扔的jsfiddle有关如何这会工作的一个例子的例子。 http://jsfiddle.net/mori57/xLJHx/
(一个有趣的后续问题应该提出自己,如果你尝试我联系你玩弄了的jsfiddle,但我并不想在这里把水搅浑)
'建立一个TD元素插入它后,给它一个文本,它等于可变的高度,并应用一个薄的坚实的红色边框。 – Ohgodwhy
我可以建议访问[jQuery API文档](http://api.jquery.com/)吗?特别是['insertAfter()'](http://api.jquery.com/insertAfter/),['text()'](http://api.jquery.com/text/)和[ 'CSS()'](http://api.jquery.com/css/)?此外,要阅读有关jQuery方法的信息,只需转到表单的URL:'http://api.jquery.com/ + methodName /',所以:'http:// api.jquery.com/insertAfter /'。 –
我只是不明白什么是