87,992
社区成员
发帖
与我相关
我的任务
分享
newCheckBox.onclick = function()
{
var pig =this.checked;
alert(pig);
pig?this.nextSibling.style.textDecoration="line-through":this.nextSibling.style.textDecoration="none";
}
<html>
<head>
<title>JS实现选中复选框后删除后面文字的效果</title>
</head>
<script type="text/javascript">
var i =0;
function AddCheckBox( )
{
//获取要添加复选框位置的
var parent = document.getElementById("addCheckBox");
//添加复选框
var newCheckBox = document.createElement("input");
newCheckBox.type = "checkbox";
//要实现, 但是却没实现
newCheckBox.onclick = function()
{
var pig =this.checked;
alert(pig);
pig?this.nextSibling.style.textDecoration="line-through":this.nextSibling.style.textDecoration="none";
}
parent.appendChild(newCheckBox);
parent.appendChild(document.createTextNode("123"+i));
//添加换行
var newLine = document.createElement("br");
parent.appendChild(newLine);
i++;
}
</script>
<body>
<div id="addCheckBox">
</div>
<input name="" type="button" value="新建复选框" onClick="AddCheckBox()" />
</body>
</html>
<html>
<head>
<title>JS实现选中复选框后删除后面文字的效果</title>
</head>
<script type="text/javascript">
function DeleteWords(field)
{
var pig = field.checked;
pig?field.nextSibling.style.textDecoration="line-through":field.nextSibling.style.textDecoration="none";
}
var i =0;
function AddCheckBox( )
{
//获取要添加复选框位置的
var parent = document.getElementById("addCheckBox");
//添加复选框
var newCheckBox = document.createElement("input");
newCheckBox.type = "checkbox";
// newCheckBox.onclick = "DeleteWords(newCheckBox)";
newCheckBox.onclick = function()
{
var pig =this.checked;
alert(pig);
pig?this.nextSibling.style.textDecoration="line-through":this.nextSibling.style.textDecoration="none";
}
parent.appendChild(newCheckBox);
//i++;为啥i在这不行
//var str= "123"+i; 怎吗让一个字符串包含换行
//给复选框后面添加文字
parent.appendChild(document.createTextNode("123"+i));
//添加换行
var newLine = document.createElement("br");
parent.appendChild(newLine);
i++;
}
</script>
<body>
<div id="addCheckBox">
</div>
<input name="" type="button" value="新建复选框" onClick="AddCheckBox()" />
</body>
</html>
<input id="newCheckBox" type="checkbox" name="aa"><label id="nextSibling">中国</label>
var newCheckBox = document.getElementById("newCheckBox");
newCheckBox.onclick = function()
{
var pig =this.checked;
//alert(pig);
pig?this.nextSibling.style.textDecoration="line-through":this.nextSibling.style.textDecoration="none";
}