纯CSS模拟按钮。单击时,该段落将变为带删除线的红色。
input[id=cb] {
display: none;
}
input[id=cb]:checked~p.strikethrough {
text-decoration: line-through;
color: red;
}
label {
border: thin solid darkgray;
border-radius: 5px;
padding: 10px;
display: inline-block;
margin-top: 5px;
}Run Code Online (Sandbox Code Playgroud)
<input name="cb" type="checkbox" id="cb">
<label for="cb">Click me</label>
<p class="strikethrough">Paragraph 1</p>
<p>Paragraph 2</p>
<p class="strikethrough">Paragraph 3</p>Run Code Online (Sandbox Code Playgroud)
您可以使用 JS 在任何元素上实现此目的。此外,您不仅可以删除
onClick,还可以将删除的内容恢复到原来的状态。
$(function(){
var $curParent, Content;
$(document).delegate("span","click", function(){
if($(this).closest("s").length) {
Content = $(this).parent("s").html();
$curParent = $(this).closest("s");
$(Content).insertAfter($curParent);
$(this).closest("s").remove();
}
else {
$(this).wrapAll("<s />");
}
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<span>click</span>/<span>click</span>
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4261 次 |
| 最近记录: |