我的网页上有两个单选框,还一个带链接图片。我想点击这个图片时,如果单选框没选中,弹出一个层。层上有关闭按钮。选中单选框,点击图片链接,导向www.baidu.com我的一些代码<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>/title>
</head><body>
<input type="radio" name="radio" id="radio" value="radio" />
<input type="radio" name="radio" id="radio2" value="radio" />
<a href="www.baidu.com"><img src="get.jpg"/></a>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>/title>
</head><body>
<input type="radio" name="radio" id="radio" value="radio" />
<input type="radio" name="radio" id="radio2" value="radio" />
<a href="www.baidu.com"><img src="get.jpg"/></a>
</body>
</html>
{
var radio = document.getElementById("radio");
var radio2 = document.getElementById("radio2");
if(radio.check || radio2.check)
document.getElementById("gobaidu").click();
else
{
//弹出层的代码*********
}
}
<script type="text/javascript">
function check() {
var radio = document.getElementsByTagName("input");
var a = document.getElementById("link");
if (radio[0].checked == false && radio[1].checked == false) {
a.href = location.href;
//div代码
}
}
</script></head>
<body>
单选框<input type="radio" name="radio" id="radio" value="radio" />
单选框<input type="radio" name="radio" id="radio2" value="radio" />
<a id="link" href="http://www.baidu.com" onclick="check()">
<img src="http://www.baidu.com/img/baidu_logo.gif" /></a>
</body>
或者动态创建层也行,方法不一
PS:刚才的代码有点小问题 <script type="text/javascript">
var imgsources = { "../pics/48(small).png": ["../pics/48.jpg", "叶依菡", "168cm"], "../pics/poy(small).png": ["../pics/poy.jpg", "Poy", "173cm"] };
function initEvent() {
for (var imgsource in imgsources) {
var img = document.createElement("img");
img.src = imgsource;
img.setAttribute("a1", imgsources[imgsource][0]);
img.setAttribute("a2", imgsources[imgsource][1]);
img.setAttribute("a3", imgsources[imgsource][2]);
img.onmouseover = showImg;
document.body.appendChild(img);
}
}
function showImg(event) {//用来支持firefox
var hiddendiv = document.getElementById("hiddendiv");
hiddendiv.style.display = "";
event = event || window.event;
hiddendiv.style.left = event.pageX + 1 || event.x + 1 ;
hiddendiv.style.top = event.pageY + 1 || event.y + 1;
document.getElementById("largeImg").src = this.getAttribute("a1");
document.getElementById("Name").innerHTML = this.getAttribute("a2");
document.getElementById("Height").innerHTML = this.getAttribute("a3");
}
function clearImg() {
document.getElementById("hiddendiv").style.display = "none";
}
</script></head>
<body onload="initEvent()">
<div id="hiddendiv" style="display: none; position: absolute;">
<img id="largeImg" src="" width="300px" height="400px" />
<p id="Name" style="font-weight: bold; color: Red">
</p>
<p id="Height">
</p>
<input type='button' value='关闭' onclick='clearImg()' />
</div>
</body>
<script type="text/javascript">
function check() {
var radio = document.getElementsByTagName("input");
var a = document.getElementById("link");
if (radio[0].checked == false && radio[1].checked == false) {
a.href = "#";
//div代码
var hidediv = document.getElementById("hide");
hidediv.style.display = "";
hidediv.style.left = event.x;
hidediv.style.top = event.y;
}
}
</script></head>
<body>
单选框<input type="radio" name="radio" id="radio" value="radio" />
单选框<input type="radio" name="radio" id="radio2" value="radio" />
<a id="link" href="http://www.baidu.com" onclick="check()">
<img src="http://www.baidu.com/img/baidu_logo.gif" /></a>
<div id="hide" style="padding: 20px 20px 20px 20px; display: none; position: absolute;
background-color: Purple;">
<input type="button" value="关闭" />
</div>
function check() {
var radio = document.getElementsByTagName("input");
var a = document.getElementById("link");
if (radio[0].checked == false && radio[1].checked == false) {
a.href = "#";
//div代码
var hidediv = document.getElementById("hide");
hidediv.style.display = "";
hidediv.style.left = event.x;
hidediv.style.top = event.y;
}
else {
a.href = "http://www.baidu.com";
}
}
function closediv() {
var hidediv = document.getElementById("hide");
hidediv.style.display = "none";
}
</script></head>
<body>
单选框<input type="radio" name="radio" id="radio" value="radio" />
单选框<input type="radio" name="radio" id="radio2" value="radio" />
<a id="link" href="http://www.baidu.com" onclick="check()">
<img src="http://www.baidu.com/img/baidu_logo.gif" /></a>
<div id="hide" style="padding: 20px 20px 20px 20px; display: none; position: absolute;">
<img src="http://csdnimg.cn/www/images/csdnindex_piclogo.gif" /><br />
<input type="button" value="关闭" onclick="closediv()" />
</div>
</body>