我正在使用asp.net mvc。
我有两个图标/图片如下:
<div class="gallery-preview-img" id="forest">
<a href="#"><img onclick="changeImage()" src="~/Content/themes/base/images/forest_icon.png"></a>
</div>
<div class="gallery-preview-img" id="urban">
<a href="#"><img onclick="changeImage()" src="~/Content/themes/base/images/urban_icon.png"></a>
</div>
脚本:
$(function changeImage() {
$('#forest').click(function () {
if (!(document.getElementById('forest').src.match('forestG'))) {
document.getElementById('forest').src = "~/Content/themes/base/images/forestG.png";
if (!(document.getElementById('urban').src.match('urban_icon')) {
document.getElementById('urban').src = "~/Content/themes/base/images/urban_icon.png";
}
}
document.getElementById('env').value = 'Forest';
})
$('#urban').click(function () {
if (!(document.getElementById('urban').src.match('urbanG')) {
document.getElementById('urban').src = "~/Content/themes/base/images/urbanG.png";
if (!(document.getElementById('forest').src != 'forest_icon')) {
document.getElementById('forest').src = "~/Content/themes/base/images/forest_icon.png";
}
}
document.getElementById('env').value = 'Urban';
});
}
});
但是图片/图标没有变化。我有什么想法吗?
答案 0 :(得分:0)