相关疑难解决方法(0)

使用javascript更改元素的类

我很难根据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")但不行.

javascript html-select onchange

0
推荐指数
1
解决办法
1万
查看次数

如何在Javascript中设置元素的类属性?

这是我生成组合框的代码。如何在其上添加 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)

javascript dom

-1
推荐指数
1
解决办法
1万
查看次数

在没有jquery库的情况下使用jQuery hover?

有没有办法使用以下代码:

$(document).ready(function () {

    $('sd').hover(function() {
      $(this).addClass('a');
    }, function() {
      $(this).removeClass('a');
    });
});
Run Code Online (Sandbox Code Playgroud)

不在我的代码中包含jquery文件?例如,有没有办法用纯JavaScript做同样的事情?

javascript jquery

-2
推荐指数
1
解决办法
3575
查看次数

单击时如何更改单选按钮的CSS

<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()的代码是什么,这样当单击单选按钮时,无线电背景会变为其他颜色,例如绿色.请帮忙,我在网上找了几个小时没有解决方案.

html javascript css onclick

-3
推荐指数
1
解决办法
9561
查看次数

标签 统计

javascript ×4

css ×1

dom ×1

html ×1

html-select ×1

jquery ×1

onchange ×1

onclick ×1