<!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=gb2312"?/>
<title>無標題文檔</title>
<style?type="text/css">
div{
?width:1000px;
?margin:0?auto;
?}
</style>
</head>
<body>
<div>
<h2?id="content">javascript能夠改變html的內容。</h2>
<script>
function?myFunction()
{
?x=document.getElementById("content");
?x.innerHTML="hello?javascript!";
?}
</script>
<button?type="button"?onclick="myFunction()">點擊這里</button>
<h2>javascript設置點擊改變圖片</h2>
<script>
function?changeimages()
{
?element=document.getElementById("img")
?if?(element.src.match("3"))
?{
?????element.src="images/2.jpg";
??}
?else{
??element.src="images/3.jpg";
??}
?
?}
</script>
<img?id="img"?onclick="changeimages()"?src="images/2.jpg"?>
<h2?id="manner">javascript能夠改變html的樣式</h2>
<script>
function?myFunction()
{
?x=document.getElementById("manner");
?x.style.color="red";
?}
</script>
<button?type="button"?onclick="myFunction()">點擊這里</button>
</div>
</body>
</html>
同樣的代碼,id為content部分寫的時候能正常運行,現在又突然不能了呢,代碼單獨拷貝又可以了
慕田峪7238772
2016-12-04 19:02:49