JavaScript:var g_preObj;function onRadioClk(radioObj) { if (g_preObj != null) { g_preObj.parent.className = "local";} radioObj.parent.className = "local ach";g_preObj = radioObj;} 不过,class名称中有空格好像不符合命名规则吧。" />

javascript控制点击后加个css进去

1" onclick="onRadioClk(this);" /> JavaScript:var g_preObj;function onRadioClk(radioObj) { if (g_preObj != null) { g_preObj.parent.className = "local";} radioObj.parent.className = "local ach";g_preObj = radioObj;} 不过,class名称中有空格好像不符合命名规则吧。
javascript控制点击后加个css进去
jquery比较简单,javascript方法比较冗余一点。。
<div><label id="1" class="local"><input name="1" type="radio" value="1" onclick="addClass(1)"></label><label id="2" class="local"><input name="1" type="radio" value="2" onclick="addClass(2)"></label><label id="3" class="local"><input name="1" type="radio" value="3" onclick="addClass(3)"></label></div><script>function addClass(str){switch(str){case 1:document.getElementById("1").className="local ach";document.getElementById("2").className="local";document.getElementById("3").className="local";break;case 2:document.getElementById("1").className="local";document.getElementById("2").className="local ach";document.getElementById("3").className="local";break;case 3:document.getElementById("1").className="local";document.getElementById("2").className="local";document.getElementById("3").className="local ach";break;default:document.getElementById("1").className="local";document.getElementById("2").className="local";document.getElementById("3").className="local";break;}}</script>2016-10-26
处理radio的onclick事件,在事件处理函数中使用对象的className来修改class的值。代码类似:
HTML:

<input name="1" type="radio" value="1" onclick="onRadioClk(this);" />
JavaScript:
var g_preObj;

function onRadioClk(radioObj) {
if (g_preObj != null) {
g_preObj.parent.className = "local";

}
radioObj.parent.className = "local ach";
g_preObj = radioObj;

}

不过,class名称中有空格好像不符合命名规则吧。2016-10-26
需要先引用jquery的库,这些代码你试试,希望可以帮到你
$(document).ready(function(){
$("input[type='radio']").click(function(){
if($(this).prop("checked")==true){
$(this).parent().addClass("ach").siblings().removeClass("ach");
}
})

})2016-10-26
mengvlog 阅读 339 次 更新于 2025-09-10 11:13:54 我来答关注问题0
  • 在JavaScript中,有三种方法可以实现点击后改变元素的样式。首先,可以直接改变元素的样式属性。例如,如果你想要改变一个id为'obj'的元素的背景颜色,可以使用以下代码:document.getElementById('obj').style.backgroundColor="#003366"其次,可以通过改变元素的class属性来实现样式改变。例如,如果你想将元...

  • 处理radio的onclick事件,在事件处理函数中使用对象的className来修改class的值。代码类似:HTML: JavaScript:var g_preObj;function onRadioClk(radioObj) { if (g_preObj != null) { g_preObj.parent.className = "local";} radioObj.parent.className = "local ach";g_preObj = radioObj;} ...

  •  QinQinMeCC javascript 怎么控制a标签的跳转

    JS控制A标记的href跳转可以按照以下方法实现:var a = document.getElementById("aHref");a.href = '/user';//取消标签原先的onclick事件,使标签点击后通过href跳转(因为无法用js跳转)a.setAttribute("onclick",'');//激发标签点击事件OVER a.click("return false");...

  •  海南加宸 jsp中点击图片后,产生3秒效果的,然后跳转其他页面;

    在JSP页面中,我们可以通过JavaScript实现点击图片后产生延迟效果,再进行页面跳转。具体实现步骤如下:首先定义一个全局变量:var time = 3;,表示3秒的延迟时间。接着编写一个函数timeOut(),用于计数和延迟跳转。函数内部首先将time减1,然后判断time是否等于0。当time等于0时,执行跳转操作。这里可以使...

  •  张三讲法 谈谈js点击之后发生了什么

        之所以突然想写这个文章,主要是之前看到一篇有意思的博文, 《探究点击事件在JavaScript事件循环中的表现》 ,有趣的地方在于JS点击事件加入回调的 并不是点击事件的回调方法 ,而是点击事件本身 (点击位置等描述点击的) 。当我们连续点击 button.a 两次的时候,结果却是 ...

檬味博客在线解答立即免费咨询

CSS相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部