举例,动态创建链接
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<title>动态添加链接</title>
<script type="text/javascript">
function AppendLink() {
var div = document.getElementById("divMain");
var linkTmp = document.createElement("a");
linkTmp.href = " http://www.baidu.com";
linkTmp.innerText = "百度"; //链接要使用innertText,不能使用value
div.appendChild(linkTmp);
}
</script>
</head>
<body>
<div id="divMain"></div>
<input type="button" value="添加链接" οnclick="AppendLink()" />
</body>
</html>
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<title>动态添加链接</title>
<script type="text/javascript">
function AppendLink() {
var div = document.getElementById("divMain");
var linkTmp = document.createElement("a");
linkTmp.href = " http://www.baidu.com";
linkTmp.innerText = "百度"; //链接要使用innertText,不能使用value
div.appendChild(linkTmp);
}
</script>
</head>
<body>
<div id="divMain"></div>
<input type="button" value="添加链接" οnclick="AppendLink()" />
</body>
</html>