请教一个关于单选效果实现的问题 能啊只要一选择调用相应的css就行了啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以radion中的onclick事件当点击后,使用js将其它的层隐藏起来,将对应的层显示出来 谢谢两位了,大概我没写清楚吧,我的目的是想点击div区域就能选中所对应的radio,因为界面上div区域比较大,相对radio比较小,所以我想实现这样一个效果。所有的radio和div都是永远显示的,一个radio对应一个div。 <SCRIPT LANGUAGE="JavaScript"><!-- function _check(otext){ document.getElementById(otext).checked = true; }//--></SCRIPT><input type="radio" name="year" id="2008">2008<input type="radio" name="year" id="2009">2009<input type="radio" name="year" id="2010">2010<br/><div style="width:40px;height:25px;border:1 solid red;float:left" onclick="_check(this.innerHTML)">2008</div><div style="width:40px;height:25px;border:1 solid red;float:left" onclick="_check(this.innerHTML)">2009</div><div style="width:40px;height:25px;border:1 solid red;float:left" onclick="_check(this.innerHTML)">2010</div> 来趁下热闹<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Image Gallery</title><script type="text/javascript" > var test = function() { var _input = event.srcElement.previousSibling.previousSibling; _input.checked = true; }</script></head><body> <input type="radio" name="test" value="1" /> <div onclick="test()">test1</div> <input type="radio" name="test" value="2" /> <div onclick="test()">test2</div> <input type="radio" name="test" value="3" /> <div onclick="test()">test3</div></body></html> 用<label>就可以实现:<!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></head><body><table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <td><input type="radio" name="year" id="2008"><label for="2008">2008<br />2008详细情况...</label></td> <td><input type="radio" name="year" id="2009"><label for="2009">2009<br />2009详细情况...</label></td> <td><input type="radio" name="year" id="2010"><label for="2010">2010<br />2010详细情况...</label></td> </tr></table></body></html> 谢谢s_liangchao1s和dada20042030的方法,都能成功,我使用了dada20042030的方法,但是没能达到一样的效果,我的部分代码如下echo "<td>";echo "<input type=radio name=\"selectedTemplate\" value=\"". $thisTemplateFilePath . "\">" . $tempaltes[$i];echo "<br>";echo "<div onclick=\"selectedTemplate()\">";drawTemplateFromFile($thisTemplateFilePath, 4);echo "</div>";echo "</td>";<SCRIPT LANGUAGE="JavaScript"> var selectedTemplate = function() { var _input = event.srcElement.previousSibling.previousSibling; _input.checked = true; }</SCRIPT>请指教下哪里有问题,是php语法上有错误吗? 使用previousSibling具有不确定性,因为不知道HTML源码的格式是怎样的.当HTML源码出现变化时,可能出现错误. 哈哈,果真有很多实现方法呀。主要就是在div的onclick事件上,修改对应的radio的checked属性就可以了。楼上的都不错! 谢谢zl_c,最后使用了你的方法,在div外套了个label,对代码的修改最少。 急求 请介绍个手机端使用的拖拽插件 第三个文本框根据前两个文本框的值 联动? js dropdownlist怎么选择指定值 单选按牛 求一个正则表达式,请大家帮帮忙啊 请问js回调函数中能包含调用其他js的函数吗? 看一下这段代码,咋输不出东西啊 js加法的问题 Java/MyEclipse ~ 求一正则表达式:实现文本框限制“8位数字+1位字母+3位数字” 帮我全面解释下面的javascript实例!!!(具体到每句都表示的意思)
radion中的onclick事件
当点击后,使用js将其它的层隐藏起来,将对应的层显示出来
<SCRIPT LANGUAGE="JavaScript">
<!--
function _check(otext){
document.getElementById(otext).checked = true;
}
//-->
</SCRIPT>
<input type="radio" name="year" id="2008">2008
<input type="radio" name="year" id="2009">2009
<input type="radio" name="year" id="2010">2010<br/>
<div style="width:40px;height:25px;border:1 solid red;float:left" onclick="_check(this.innerHTML)">2008</div>
<div style="width:40px;height:25px;border:1 solid red;float:left" onclick="_check(this.innerHTML)">2009</div>
<div style="width:40px;height:25px;border:1 solid red;float:left" onclick="_check(this.innerHTML)">2010</div>
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Image Gallery</title>
<script type="text/javascript" >
var test = function()
{
var _input = event.srcElement.previousSibling.previousSibling;
_input.checked = true;
}
</script>
</head>
<body>
<input type="radio" name="test" value="1" />
<div onclick="test()">test1</div>
<input type="radio" name="test" value="2" />
<div onclick="test()">test2</div>
<input type="radio" name="test" value="3" />
<div onclick="test()">test3</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body><table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="radio" name="year" id="2008"><label for="2008">2008<br />2008详细情况...</label></td>
<td><input type="radio" name="year" id="2009"><label for="2009">2009<br />2009详细情况...</label></td>
<td><input type="radio" name="year" id="2010"><label for="2010">2010<br />2010详细情况...</label></td>
</tr>
</table>
</body>
</html>
echo "<td>";
echo "<input type=radio name=\"selectedTemplate\" value=\"". $thisTemplateFilePath . "\">" . $tempaltes[$i];
echo "<br>";
echo "<div onclick=\"selectedTemplate()\">";
drawTemplateFromFile($thisTemplateFilePath, 4);
echo "</div>";
echo "</td>";<SCRIPT LANGUAGE="JavaScript">
var selectedTemplate = function()
{
var _input = event.srcElement.previousSibling.previousSibling;
_input.checked = true;
}
</SCRIPT>
请指教下哪里有问题,是php语法上有错误吗?