-
根据输入的次数,多次输出"HelloWorld"
<script type="text/javascript">
document.write("Hello World");
var j=prompt("请输入连续输出标题3的次数:","")
for(var i=0;i<j;i++){
document.write("<h3>Hello World</h3>");
}
document.write("<h1>Hello World</h1>");
alert("共连续输出标题:"+j+"次");
</script>
运行结果:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>程序调试</title>
<script type="text/javascript">
var t=prompt("请输入一个整数","");
if(t>5){
for(var i=t;i>0;i--){
for(var j=0;j<i;j++){
document.write("* ");
}
document.write("<br />");
}
}
else{
for(var k=t;k>0;k--){
for(var m=0;m<k;m++){
document.write("* ");
}
document.write("<br />");
}
for(var n=1;n<=t;n++){
for(var h=0;h<n;h++){
document.write("* ");
}
document.write("<br />");
}
}
</script>
</head>
运行结果:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>动态改变表格内容</title>
<style type="text/css">
td{ font-size:13px;
border-bottom:1px solid #cccccc;
border-right:1px solid #cccccc;
}
</style>
</head>
<body>
<table width="600" cellspacing="0" cellpadding="0" style="border-top:1px solid #cccccc;border-left:1px solid #cccccc;border-bottom:1px solid #cccccc;">
<tr>
<td style=" text-align:center; font-size:16px; font-weight:bold;height:35px;">我的购物车</td>
</tr>
<tr><td style="border:0;">
<table width="100%" cellspacing="0" cellpadding="0" id="Table1">
<tr>
<td style=" text-align:center; font-weight:bold; height:35px;">商品名称</td>
<td style="width:90px; text-align:center; font-weight:bold;"> 数量(个)</td>
<td style="width:90px; text-align:center; font-weight:bold;">价格(元)</td>
<td style="text-align:center;width:180px; font-weight:bold;">操作</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style=" text-align:center; height:30px;border-bottom:0;"><input name="add" type="button" value="添加一行" onclick="build_row()"/> <input name="sub" type="button" value="提交定单" /></td>
</tr>
</table>
<script type="text/javascript">
<!--
//建立一个函数build_row()用于建立新的一行
var row_index=0;
function build_row(){
row_index++;
var new_row=Table1.insertRow(Table1.rows.length);
new_row.setAttribute("id", "row"+row_index);
var new_col=new_row.insertCell(0);
new_col.innerHTML="攀高搓捶背靠垫按摩器(蓝色 )";
new_col.style.height="30";
new_col.style.textAlign="center";
var new_col=new_row.insertCell(1);
new_col.innerHTML="3";
new_col.style.textAlign="center";
var new_col=new_row.insertCell(2);
new_col.innerHTML="¥450.50";
new_col.style.textAlign="center";
var new_col=new_row.insertCell(3);
new_col.innerHTML="<input type='button' value='删除' name='del"+row_index+"' onclick=\"delete_row('row"+row_index+ "')\"> <input type='button' value='编辑' name='edit"+row_index+"' onclick=\"edits_row('row"+row_index+ "')\">";
new_col.style.textAlign="center";
}
//建立一个函数delete_row用于删除一行
function delete_row(rname)
{
if(!Table1)
{
return ;
}
var i;
i=Table1.rows(rname).rowIndex;
// alert(i);
Table1.deleteRow(i);
}
function edits_row(num)
{
var i;
i=Table1.rows(num).rowIndex;
Table1.rows(i).cells(0).innerHTML="<input type='text' name='names' value='攀高搓捶背靠垫按摩器(蓝色 )' style='width:200px;'/> ";
Table1.rows(i).cells(1).innerHTML="<input type='text' name='nums' value='3' style='width:30px;'/> ";
Table1.rows(i).cells(2).innerHTML="<input type='text' name='price' value='¥450.50' style='width:70px;'/> ";
}
build_row();
-->
</script>
</body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>广告专栏</title>
<style type="text/css">
body{margin:0;}
</style>
</head>
<body>
<img src="images/indextop.gif" width="780" height="238" />
</body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>弹出窗口</title>
<script type="text/javascript">
window.open("adv.html", "广告窗口", "toolbar=0, scrollbars=0, location=0, status=0, menubar=0, resizable=0, width=780, height=210,top=200,left=150");
/*
width:弹出窗口的宽度
height:弹出窗口的高度
top:弹出窗口离屏幕顶部距离
left:弹出窗口离屏幕左边距离
*/
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="height:30px;"> </td>
</tr>
<tr>
<td style="text-align:center;"><img src="images/bg.jpg" width="864" height="489" /></td>
</tr>
<tr>
<td> </td>
</tr>
</table>