更改checkbox效果

pubaolin 2009-12-07 04:43:43
checkbox的默认被选中效果是在框里画了个钩,我想用JS把它改成一个全黑的框,有什么办法?
...全文
87 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yixianggao 2009-12-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 pubaolin 的回复:]
不错,呵呵
能不能让黑框的大小和checkbox内框大小一样?给人的感觉就像把框内涂成了黑色
[/Quote]

IE 7 下可以达到 lz 要求,FF 行不通!
不过 margin-top 居然是 -22px 才能达到效果,太诡异了!

写着玩吧!

L@_@K
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>

<body>
<div style="width: 12px; height: 12px; border: solid 0px red; overflow: hidden; margin-bottom: 5px;">
<input type="checkbox" id="iptChk1" style="margin: -22px 0px 0px -4px;" />
</div>
<div style="width: 12px; height: 12px; border: solid 0px red; overflow: hidden; margin-bottom: 5px;">
<input type="checkbox" id="iptChk2" style="margin: -22px 0px 0px -4px;" />
</div>
<script type="text/javascript">
<!--
var chk = document.getElementById("iptChk1");
chk.onclick = function() {
if (this.checked)
{
this.style.border = "solid 10px black";
}
else
{
this.style.border = "solid 0px black";
}
};
//-->
</script>
</body>
</html>
pubaolin 2009-12-07
  • 打赏
  • 举报
回复
不错,呵呵
能不能让黑框的大小和checkbox内框大小一样?给人的感觉就像把框内涂成了黑色
xiuyouxu 2009-12-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yixianggao 的回复:]
IE 下可以这么玩,FF 下不行,可以考虑用 div 遮罩实现

L@_@K
HTML code<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title> new document</title><metaname="generator" content="editplus"/><metaname="author" content=""/><metaname="keywords" content=""/><metaname="description" content=""/></head><body><inputtype="checkbox" id="iptChk1"/><inputtype="checkbox" id="iptChk2"/><scripttype="text/javascript"><!--var chk= document.getElementById("iptChk1");
chk.onclick=function() {if (this.checked)
{this.style.border="solid 10px black";
}else
{this.style.border="solid 0px black";
}
};//--></script></body></html>
[/Quote]
up
yixianggao 2009-12-07
  • 打赏
  • 举报
回复
IE 下可以这么玩,FF 下不行,可以考虑用 div 遮罩实现

L@_@K
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>

<body>
<input type="checkbox" id="iptChk1" />
<input type="checkbox" id="iptChk2" />
<script type="text/javascript">
<!--
var chk = document.getElementById("iptChk1");
chk.onclick = function() {
if (this.checked)
{
this.style.border = "solid 10px black";
}
else
{
this.style.border = "solid 0px black";
}
};
//-->
</script>
</body>
</html>
pubaolin 2009-12-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sohighthesky 的回复:]
用2张图片,勾选和未勾选
将checkbox样式CSS code style="filter:alpha(opacity=0);opacity:0"
[/Quote]
不明白,给个完整代码行吗
sohighthesky 2009-12-07
  • 打赏
  • 举报
回复
用2张图片,勾选和未勾选
将checkbox样式
 style="filter:alpha(opacity=0);opacity:0"

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧