Jquery e')。删除(); $('.no').remove(); //构建总尺寸为x总尺寸的二维表格 var total=$(this.val() var newTable=$('Lesile Matrix:'); var i=0; 而(i
这是一个在IE7中也能正常工作的演示:Jquery e')。删除(); $('.no').remove(); //构建总尺寸为x总尺寸的二维表格 var total=$(this.val() var newTable=$('Lesile Matrix:'); var i=0; 而(i,jquery,internet-explorer,internet-explorer-7,appendto,Jquery,Internet Explorer,Internet Explorer 7,Appendto,这是一个在IE7中也能正常工作的演示: 或者,这里有一个更简单的版本,只需将HTML构造成字符串,然后一次将HTML全部追加: var html = '<table class="leslie" border="0" align="center"><tr><th width="5">Lesile Matrix:</th></tr>'; html += '<tr><td><input type="text"
或者,这里有一个更简单的版本,只需将HTML构造成字符串,然后一次将HTML全部追加:
var html = '<table class="leslie" border="0" align="center"><tr><th width="5">Lesile Matrix:</th></tr>';
html += '<tr><td><input type="text" size="5" name="a" value="0" id="id_a"/></td></tr>';
html += '</table>';
$(html).appendTo(document.body);
$('#id_S').change(function() {
// remove previous tables
$('.leslie').remove();
$('.no').remove();
var total = $(this).val()
// construct 2-D table that is total x total in size
var html = '<table class="leslie" border="0" align="center"><tr><th width="5" colspan=' + total + '>Lesile Matrix:</th></tr>';
for (var i = 0; i < total; i++) {
html += '<tr>';
for (var j = 0; j < total; j++) {
html += '<td><input type="text" size="5" name="a' + i + '' + j + '" value="0" id="id_a' + i + '' + j + '"/></td>';
}
html += '</tr>';
}
html += "</table>";
$(".table").append(html);
// create our second table
html = '<table class="no" border="0" align="center"><tr><th width="5">Initial Number:</th></tr>';
for (var q = 0; q < total; q++) {
html += '<tr><td><input type="text" size="5" name="no' + q + '" value="0" id="id_a' + q + '"/></td></tr>';
}
html += '</table>';
$(".table").append(html);
})
$('#id_S')。更改(函数(){
//删除以前的表
$('.leslie').remove();
$('.no').remove();
var total=$(this.val()
//构建总尺寸为x总尺寸的二维表格
var html='Lesile Matrix:';
对于(变量i=0;i
此版本的工作演示:您没有正确使用DOM/jQuery。DOM(或者jQuery,它是一个DOM包装器,混合了其他东西)不能单独操作open和close标记,它只能同时操作它们。如果将部分HTML传递给jQuery,它将使用DOM API构造DOM对象。在您的情况下,IE7DOM无法理解部分HTML的含义 以下方面应起作用:
<script type="text/javascript" src=" ../stylesheets/jquery-1.7.2.js"></script>
<script>
$('<table class="leslie" border="0" align="center"><tr><th width="5">Lesile Matrix:</th></tr></table>').appendTo('.table');
$('<tr>').appendTo('.leslie');
$('<td><input type="text" size="5" name="a" value="0" id="id_a"/></td>').appendTo('.leslie tr:last');
</script>
$('Lesile-Matrix:').appendTo('.table');
$('').appendTo('.leslie');
$('').appendTo('.leslie tr:last');
前提是,当您使用HTML调用
$(…)
时,应该始终传入有效的HTML 您没有正确使用DOM/jQuery。DOM(或者jQuery,它是一个DOM包装器,混合了其他东西)不能单独操作open和close标记,它只能同时操作它们。如果将部分HTML传递给jQuery,它将使用DOM API构造DOM对象。在您的情况下,IE7DOM无法理解部分HTML的含义
以下方面应起作用:
<script type="text/javascript" src=" ../stylesheets/jquery-1.7.2.js"></script>
<script>
$('<table class="leslie" border="0" align="center"><tr><th width="5">Lesile Matrix:</th></tr></table>').appendTo('.table');
$('<tr>').appendTo('.leslie');
$('<td><input type="text" size="5" name="a" value="0" id="id_a"/></td>').appendTo('.leslie tr:last');
</script>
$('Lesile-Matrix:').appendTo('.table');
$('').appendTo('.leslie');
$('').appendTo('.leslie tr:last');
前提是,当您使用HTML调用
$(…)
时,应该始终传入有效的HTML 不幸的是,很多东西在IE7中不起作用。。。如果你问我,所有的网络标准都是其中之一。我感到很遗憾,你必须支持IE7。这里已经回答了类似的问题:[jquery bug appendTo in IE7][1][1]:@tao.hong我认为支持的功能列表更短。我强烈建议阅读更多关于jquery中dom操作的内容;创建此表的方式效率很低,更不用说$(“”)
没有按照您认为的方式进行操作。您使用的.appendTo()
不正确。它不是字符串连接,所以用它来附加结束标记是错误的。不幸的是,很多东西在IE7中不起作用。。。如果你问我,所有的网络标准都是其中之一。我感到很遗憾,你必须支持IE7。这里已经回答了类似的问题:[jquery bug appendTo in IE7][1][1]:@tao.hong我认为支持的功能列表更短。我强烈建议阅读更多关于jquery中dom操作的内容;创建此表的方式效率很低,更不用说$(“”)
没有按照您认为的方式进行操作。您使用的.appendTo()
不正确。这不是字符串连接,所以用它来附加结束标记是错误的。我明白了。但我认为新的IE支持附加HTML对象的元素@tao.hong这是真的(支持附加元素)。但您仍然必须正确地连接它们。正确的方法是jfriend00说,写完整的对象,即使用闭合的标记,然后附加。您不能附加对象的一部分,然后稍后再将其关闭。@tao.hong-在您的JSFIDLE中,浏览器试图通过创建部分对象来了解您到底在做什么。它只能生成整个对象,所以它会尝试猜测您要做什么。当您尝试猜测时,您将无法在浏览器中获得可预测的行为。@tao.hong另外,在$()
中使用复杂的html将导致以后的麻烦,因为jQuery将该方法收紧,转而使用$.parseHTML()
要从html字符串创建dom节点。@tao.hong-IE7中肯定还有其他事情,因为我的代码在IE7中工作得非常好:我明白了。但我认为新的IE支持附加HTML对象的元素@tao.hong这是真的(支持附加元素)。但您仍然必须正确地连接它们。正确的方法是jfriend00说,写完整的对象,即使用闭合的标记,然后附加。您不能附加对象的一部分,然后稍后再将其关闭。@tao.hong-在您的JSFIDLE中,浏览器试图通过创建部分对象来了解您到底在做什么。它只能生成整个对象,所以它会尝试猜测您要做什么。当您尝试猜测时,您将无法在浏览器中获得可预测的行为。@tao.hong同时,在$()
中使用复杂的html将
var html = '<table class="leslie" border="0" align="center"><tr><th width="5">Lesile Matrix:</th></tr>';
html += '<tr><td><input type="text" size="5" name="a" value="0" id="id_a"/></td></tr>';
html += '</table>';
$(html).appendTo(document.body);
$('#id_S').change(function() {
// remove previous tables
$('.leslie').remove();
$('.no').remove();
// construct 2-D table that is total x total in size
var total = $(this).val()
var newTable = $('<table class="leslie" border="0" align="center"><tr><th width="5" colspan=' + total + '>Lesile Matrix:</th></tr></table>');
var i = 0;
while (i < total) {
// create new row
var newRow = $('<tr>').appendTo(newTable);
var j = 0;
while (j < total) {
// create new cell and append it to the current row
$('<td><input type="text" size="5" name="a' + i + '' + j + '" value="0" id="id_a' + i + '' + j + '"/></td>').appendTo(newRow);
j = j + 1;
}
// add this row to the table
newRow.appendTo(newTable);
i = i + 1;
}
// add the fully formed table to the document
newTable.appendTo('.table');
// create out second table
newTable = $('<table class="no" border="0" align="center"><tr><th width="5">Initial Number:</th></tr></table>');
var q = 0;
while (q < total) {
// create a new row and add it to the new table
$('<tr><td><input type="text" size="5" name="no' + q + '" value="0" id="id_a' + q + '"/></td></tr>').appendTo(newTable);
q = q + 1;
}
// add this fully formed table to the document
newTable.appendTo(".table");
})
$('#id_S').change(function() {
// remove previous tables
$('.leslie').remove();
$('.no').remove();
var total = $(this).val()
// construct 2-D table that is total x total in size
var html = '<table class="leslie" border="0" align="center"><tr><th width="5" colspan=' + total + '>Lesile Matrix:</th></tr>';
for (var i = 0; i < total; i++) {
html += '<tr>';
for (var j = 0; j < total; j++) {
html += '<td><input type="text" size="5" name="a' + i + '' + j + '" value="0" id="id_a' + i + '' + j + '"/></td>';
}
html += '</tr>';
}
html += "</table>";
$(".table").append(html);
// create our second table
html = '<table class="no" border="0" align="center"><tr><th width="5">Initial Number:</th></tr>';
for (var q = 0; q < total; q++) {
html += '<tr><td><input type="text" size="5" name="no' + q + '" value="0" id="id_a' + q + '"/></td></tr>';
}
html += '</table>';
$(".table").append(html);
})
<script type="text/javascript" src=" ../stylesheets/jquery-1.7.2.js"></script>
<script>
$('<table class="leslie" border="0" align="center"><tr><th width="5">Lesile Matrix:</th></tr></table>').appendTo('.table');
$('<tr>').appendTo('.leslie');
$('<td><input type="text" size="5" name="a" value="0" id="id_a"/></td>').appendTo('.leslie tr:last');
</script>