【发布时间】:2015-04-24 04:55:09
【问题描述】:
我一遍又一遍地翻阅我的代码,我就是不明白为什么它不能正常工作......
有人可以启发我吗?这里有什么问题?我只是没看到。
代码应允许用户在文本框中输入各种值来更改图像的某些特征,例如边框大小、颜色、宽度、高度、图像替代文本和图像标题。
这是我的代码:
<html>
<head>
<title>Image Properties</title>
<script type="text.javascript">
function changeImage() {
//applies a new border size
document.getElementById('img').border = document.getElementById('bs').value;
//applies a new border color
document.getElementById('img').style.borderColor = document.getElementById('bc').value;
//applies a new width
document.getElementById('img').width = document.getElementById('bw').value;
//applies a new height
document.getElementById('img').height = document.getElementById('bh').value;
//applies a new alt tag
document.getElementById('img').alt = document.getElementById('ba').value;
//applies a new title
document.getElementById('img').title = document.getElementById('bt').value;
}
</script>
</head>
<body>
<h2>Change Image Properties</h2>
<img src="KotakuLogo.jpg" id="img" />
<p>
Border Size:<input type="text" id="bs"
onfocus="this.style.background='#c3c3c3'"
onblur="this.style.background='#FFFFFF'"/><br />
New Border Color:<input type="text" id="bc"
onfocus="this.style.background='#c3c3c3'"
onblur="this.style.background='#FFFFFF'"/><br />
New Border Width:<input type="text" id="bw"
onfocus="this.style.background='#c3c3c3'"
onblur="this.style.background='#FFFFFF'"/><br />
New Border Height:<input type="text" id="bh"
onfocus="this.style.background='#c3c3c3'"
onblur="this.style.background='#FFFFFF'"/><br />
New Border Alt Tag:<input type="text" id="ba"
onfocus="this.style.background='#c3c3c3'"
onblur="this.style.background='#FFFFFF'"/><br />
New Border Title:<input type="text" id="bt"
onfocus="this.style.background='#c3c3c3'"
onblur="this.style.background='#FFFFFF'"/><br />
<input type="button" value="Submit Image Changes" onclick="changeImage()" />
</body>
</html>
【问题讨论】:
标签: javascript html image