单击时,添加类,直到复选框/标签单击关闭
On click, add class until checkbox/label clicked off
Context:
我正在使用精灵表和jQuery设置复选框样式。
我希望"焦点"状态的行为与这个免费的HTML5模板上的复选框完全相同:
通过"焦点"/"模糊",我指的是复选框周围的彩色边框:
- 。出现在选项卡进入复选框上,单击复选框或单击标签。
- 。在 Tab 上消失在复选框外、单击退出复选框或单击关闭标签上。
我的代码:
到目前为止,我只在跳入/跳出复选框时实现了所描述的"焦点"/"模糊"。
作为JSFiddle:
http://jsfiddle.net/k9mgh8rz/4/
作为 HTML 页面:
(CDN 脚本在发布为堆栈溢出代码段时不会加载)。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
input[type="text"],
input[type="password"] {
border: 1px solid black;
padding: 5px;
}
input[type="text"]:focus,
input[type="password"]:focus {
border: 1px solid red;
}
label {
cursor: pointer;
}
.forgetmenot span {
display: inline-block;
margin-left: 15px;
position: relative;
top: 3px;
}
/* iCheck Plugin (Skin for check-box)
----------------------------------- */
.icheckbox_minimal {
display: inline-block;
*display: inline;
vertical-align: middle;
margin: 0;
padding: 0;
width: 30px;
height: 30px;
background: url(http://s10.postimg.org/lzj62spk5/check_boxes.png) no-repeat;
border: none;
cursor: pointer;
}
.icheckbox_minimal {
background-position: 0 0;
}
.icheckbox_minimal.checked {
background-position: -60px 0;
}
.icheckbox_minimal.focus {
background-position: -30px 0;
}
.icheckbox_minimal.checked.focus {
background-position: -90px 0;
}
/* HiDPI support */
@media (-o-min-device-pixel-ratio: 5/4),
(-webkit-min-device-pixel-ratio: 1.25),
(min-resolution: 120dpi),
(min-resolution: 1.25dppx) {
.icheckbox_minimal {
background-image: url(http://s16.postimg.org/k51empanp/check_boxes_2x.png);
-webkit-background-size: 200px 20px;
background-size: 200px 20px;
}
}
</style>
</head>
<body>
<!--Mark-up cannot be edited for the purposes of the required solution.-->
<p>
<label for="user_login">Username<br>
<input class="input" id="user_login" name="log" size="20" type="text" value="">
</label>
</p>
<p>
<label for="user_pass">Password<br>
<input class="input" id="user_pass" name="pwd" size="20" type="password" value="">
</label>
</p>
<p class="forgetmenot">
<label for="rememberme">
<input id="rememberme" name="rememberme" type="checkbox" value="forever"> Remember Me
</label>
</p>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.1.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/iCheck/1.0.1/icheck.js"></script>
<script>
$(document).ready(function() {
//Add span for styling.
$('#rememberme').each(function() {
$(this.nextSibling).wrap('<span><'/span>');
});
//Apply iCheck
$('input').iCheck({
checkboxClass: 'icheckbox_minimal'
});
});
</script>
</body>
</html>
我的问题:
使用上面的JSFiddle,仅修改jQuery和CSS(而不是标记),如何实现所描述的"焦点"/"模糊",单击复选框并单击标签的开/关?
像这样:
$('input').on('click change', function()
{
$('input').css('border-color', 'black'); // reset all inputs to black
$(this).css('border-color', 'red'); // define the current one as red
});
相关文章:
- 单击标签后,使用Javascript更改正文CSS
- 如果在使用IE 7或8时隐藏,则单击标签不选中复选框
- 单击标签,如果复选框道具检查为真
- 如何动态单击标签以仅检查整行
- 只需单击标签即可双击
- 单击标签时获取其 ID
- 如何在 MVC 应用程序中单击标签时选中所有复选框
- 当单击
- 标签下的标签时,我想将活动类添加到该
- 标签中
- JavaScript 在选中复选框时通过单击标签进行确认
- 单击标签时未单击复选框
- 使用ajax打印“;测试”;单击标签时显示到屏幕
- 真棒获取并单击标签属性
- 单击标签应选择无线电输入
- 向下滑动一次单击标签不会滑动
- 无法在Javascript中单击标签
- 单击标签,选择一个选项
- 如何创建单击标签时向左滑动的搜索栏?
- 我如何使用document.getElementById(someid).单击标签a
- 复选框& # 39;改变# 39;事件在单击标签时起作用.ie8, ie7
- 如何使复选框在单击标签时被选中
- 标签下的标签时,我想将活动类添加到该