关闭创建的jQuery元素 [英] Closing Created jQuery Elements
问题描述
我有这个问题:
$(document).ready(function(){
$(' (function)(){
$ .get('/ WebTestProject / ServletEsempio',function(responseJson){
var $ table = $('< table>)。appendTo ($('#result'));
$ .each(responseJson,function(index,product){
$('< tr>')。appendTo($ table)
.append($('< td>').text(index))
.append($('< td>).text(product))
});
});
});
});
这段代码可以调用我的servlet,但是我没有找到如何关闭TAG和。
是可能的吗?
非常感谢所有人。
当您以这种方式使用jQuery创建元素时,会自动创建自动关闭。但是,即使jQuery文档也建议您明确地关闭它:
为了确保跨平台兼容性,代码片段必须格式良好。 包含其他元素的标签应该与结束标记配对:
即:
$('< table /&c'c>或
$('< table>< / table>);
不能包含元素的标签可能会被快速关闭或不被包含:
即:
$('< img />');
或$('< input>');
源: http://api.jquery.com/jQuery/#creating-new-elements
i have this problem:
$(document).ready(function() {
$('#buttonTest').click(function() {
$.get('/WebTestProject/ServletEsempio', function(responseJson) {
var $table = $('<table>').appendTo($('#result'));
$.each(responseJson, function(index, product) {
$('<tr>').appendTo($table)
.append($('<td>').text(index))
.append($('<td>').text(product))
});
});
});
});
this code is OK for calling my servlet, but i dont find how to close the TAG , and . is it possible?
many thanks to all.
When you create elements using jQuery in this fashion, they are created automatically closed. However, even the jQuery documentation recommends that you close it explicitly:
To ensure cross-platform compatibility, the snippet must be well-formed. Tags that can contain other elements should be paired with a closing tag:
ie:
$('<table />');
or$('<table></table>');
Tags that cannot contain elements may be quick-closed or not:
ie:
$('<img />');
or$('<input>');
Source: http://api.jquery.com/jQuery/#creating-new-elements
这篇关于关闭创建的jQuery元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!