我需要在html
页面中添加三角形,我还需要将每一行放在p tag
中以检查其是偶数还是奇数
var line = '<p class = odd>'
var l = " ";
var myDiv = $('<div id = "container"></div>')
$('body').append(myDiv)
var randColor = '#' +(Math.random()*0xFFFFFF<<0).toString(16);
for (var i = 1; i <= input; i++) {
for (var j = 0; j <= input-i ; j++) {
$('#container').css('color',randColor)
$("#container").append( line + i);
}
$("#container").append(l);
}
答案 0 :(得分:0)
试试这个......
var line = '<p class = odd>'
var l = "</p>";
var myDiv = $('<div id = "container"></div>')
$('body').append(myDiv)
var randColor = '#' +(Math.random()*0xFFFFFF<<0).toString(16);
var str="";
for (var i = 1; i <= input; i++) {
for (var j = 0; j <= input-i ; j++) {
str+=i;
}
}
$("#container").append( line + str+l);