我有以下设置,其中添加了自定义选中标记以设置单选按钮的样式。
但它也会在文本类型输入中添加该复选标记。
var changed =function(){
Array.from(document.querySelectorAll("table")).forEach((element,index) =>
{
Array.from(element.querySelectorAll("input")).forEach((myinp,index) =>
{
if(myinp.checked==true){
myinp.parentNode.parentNode.classList.add("active");
}else{
myinp.parentNode.parentNode.classList.remove("active");
}
});
});
}//changed function ends
Array.from(document.querySelectorAll("table")).forEach((element,index) =>
{
Array.from(element.querySelectorAll("input")).forEach((myinp,index) =>
{
var checkmark = document.createElement("span");
checkmark.classList.add("checkmark");
myinp.parentNode.appendChild(checkmark);
myinp.addEventListener("change", changed);
});
});
table tbody tr td:first-child{
position:relative;
}
.confirmit-table tbody tr input[type='radio'][type='checkbox']{
visibility:hidden
}
/*Create a custom checkbox */
.checkmark,.dotmark {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 25px;
background-color: #eee;
}
input[type='text']{
width:20px;
}
/* On mouse-over, add a grey background color */
table tbody tr:hover input ~ .checkmark {
background-color: #ccc;
}
/* On mouse-over, add a grey background color */
table tbody tr:hover input ~ .dotmark {
background-color: #ccc;
}
/* When the checkbox is checked, add a blue background */
table tbody tr input:checked ~ .checkmark {
background-color:#11448d;
}
/* When the checkbox is checked, add a blue background */
table tbody tr input:checked ~ .dotmark {
background-color:#11448d;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after,.dotmark:after {
content: "";
position: absolute;
display: none;
top:50%;
}
/* Show the checkmark when checked */
table tbody tr input:checked ~ .checkmark:after{
display: block;
}
/* Show the checkmark when checked */
table tbody tr input:checked ~ .dotmark:after{
display: block;
}
/* Style the checkmark/indicator */
table tbody tr .checkmark:after {
left: 9px;
top: 30%;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
table tbody tr .dotmark:after {
left: 8px;
top: 8px;
width: 10px;
height: 10px;
background-color:#fff;
}
/*Custom check boxes/radio buttons*/
table label {
width:350px;
display:block;
margin:0px;
padding:5px 10px;
}
table label:hover{
margin:0px;
}
.confirmit-table tbody tr{
background-color:#f5f5f5;
}
.active{
background:#6081b9 !important;
}
<table>
<tr>
<td>
<input id='txt1' type='text' name='test'>
</td>
<td>
<label for='txt1'>Text Input1</label>
</td>
</tr>
<tr>
<td>
<input id='txt2' type='text' name='test'>
</td>
<td>
<label for='txt2'>Text input 2</label>
</td>
</tr>
<tr>
<td>
<input id='inp1' type='radio' name='test'>
</td>
<td>
<label for='inp1'>Radio button 1</label>
</td>
</tr>
<tr>
<td>
<input id='inp2' type='radio' name='test'>
</td>
<td>
<label for='inp2'>Radio button 2</label>
</td>
</tr>
<tr>
<td>
<input id='inp3' type='radio' name='test'>
</td>
<td>
<label for='inp3'>Radio button 3</label>
</td>
</tr>
</table>
我已经使用javascript设置了单选按钮的样式(即,在单选类型输入旁边添加了自定义选中标记元素),但是我不希望这种样式仅在javascript中应用文本类型输入。
如何从querySelectorAll(“input”)中排除文本类型输入
最佳答案
console.log(document.querySelectorAll('input:not([type=text])'));