求高手用javascript做一个页面可以动态生成HTML
发布网友
发布时间:2022-04-29 01:55
我来回答
共2个回答
热心网友
时间:2022-04-21 07:29
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>生成html文档</title>
<script type="text/javascript" language="javascript">
function btnSureClick(){
var input=document.getElementById("tbxInput").value;
var area="<a id="+input+" href=\'#\' target=\'_blank\'>"+input+"</a>";
document.getElementById("area").innerHTML=area;
document.getElementById("txt").innerText=area;
}
</script>
</head>
<body>
<table>
<tr><td>
<input type="text" id="tbxInput" />
<input type="button" value="确定" id="btnSure" onclick="btnSureClick()"/>
</td>
</tr>
<tr>
<td>
<textarea id="area" rows="5" ></textarea>
<textarea id="txt" rows="5" cols="50"></textarea>
<td>
</tr>
</table>
</body>
</html>
另存为 ***.html 文件,运行
热心网友
时间:2022-04-21 08:47
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
<!--
function action(){
var num = document.getElementById("number").value;
if(num == ""){
alert("您没有填写内容");
return;
}else if(isNaN(num)){
alert("必需填写数字");
document.getElementById("number").value="";
return;
}else{
document.write("<a id='"+num+"' href='#' target='_blank'>"+num+"</a>");
}
}
//-->
</script>
</HEAD>
<BODY>
<input name="number" id="numbner" type="text"><br>
<input name="but" id="but" type="button" onclick="action()"><br>
</BODY>
</HTML>