我有 menu.html 页面,在该页面中,我有环境、噪音、污染等类别。每个类别都有子类别。基于类别和子类别的选择,我必须在下一页显示不同的图像和不同的字体颜色......
HTML / JavaScript中的任何想法/建议....
谢谢库马尔
我有 menu.html 页面,在该页面中,我有环境、噪音、污染等类别。每个类别都有子类别。基于类别和子类别的选择,我必须在下一页显示不同的图像和不同的字体颜色......
HTML / JavaScript中的任何想法/建议....
谢谢库马尔
<script type="text/javascript">
function changeImage(){
var selectBox = document.getElementById("selectbox");
var selectedValue = selectBox.options[selectBox.selectedIndex].value;
document.getElementById("img").src = selectedValue + ".png";
}
</script>
You can check the value of the selected with selectBox.options[selectBox.selectedIndex].innerHTML
too. That will make it easier if you have a lot of options and do not want to set the value of everything.
If the images on your server have the same names as the value of each option, you don't even need to use a if statement. However, if the images are in different places or have different names/extensions, you can set the code like this:
<script type="text/javascript">
function changeImage(){
var selectBox = document.getElementById("selectbox");
var selectedValue = selectBox.options[selectBox.selectedIndex].value;
var img = document.getElementById("img");
if (selectedValue == "html"){
img.src = "images/html.png";
} else if (selectedValue == "css"){
img.src = "images/css.jpeg";
}
}
</script>
CSS类呢?您可以为特定类提供字体颜色和背景图像。
如果您要链接到另一个页面,您可以将查询字符串添加到URL
并从第二个页面对其进行操作。
<a href="page.html?font=red&image=pollusion">Pollusion</a>