我很难根据select标签中的选定项目更改元素类.这是我的代码:
<table>
<tr>
<select onchange="wow(this.value)">
<option value="a">a</option>
<option value="b">b</option>
</select>
</tr>
<tr id="x" class="show">
x
</tr>
</table>
<script>
function wow(value){
switch(value){
case "a": document.getElementById("x").className = "show"; break;
case "b": document.getElementById("x").className = "hide"; break;
}
}
</script>
<style>
.show{
display:inline-block;
}
.hide{
display:none;
}
</style>
Run Code Online (Sandbox Code Playgroud)
我在这里没有看到任何问题.我也试过setAttribute("class", "show")但不行.
这是我生成组合框的代码。如何在其上添加 css 类名“chosen-select”?
var cell3 = row.insertCell(2);
var element2 = document.createElement("select");
var option1 = document.createElement("option");
option1.value="";
option1.innerHTML="--Select--";
element2.appendChild(option1);
var option2 = document.createElement("option");
option2.value="1";
option2.innerHTML="Apple";
element2.appendChild(option2);
element2.name = "description" + rowno;
element2.id = "description" + rowno;
element2.setAttribute("required","true");
element2.style.width = "150px";
cell3.appendChild(element2);
Run Code Online (Sandbox Code Playgroud) 有没有办法使用以下代码:
$(document).ready(function () {
$('sd').hover(function() {
$(this).addClass('a');
}, function() {
$(this).removeClass('a');
});
});
Run Code Online (Sandbox Code Playgroud)
不在我的代码中包含jquery文件?例如,有没有办法用纯JavaScript做同样的事情?
<style type="text/css">
.radiostyle {
background-color: #999;
}
</style>
<label for="a1" class="radiostyle">
<Input type = radio Name = 1 Value = 100 Onclick="changecss()" id="a1">
100 bucks</label>
Run Code Online (Sandbox Code Playgroud)
函数changecss()的代码是什么,这样当单击单选按钮时,无线电背景会变为其他颜色,例如绿色.请帮忙,我在网上找了几个小时没有解决方案.