您现在的位置是:首页 > 电脑技术查询 > web开发

怎么改变input的style属性

编辑:chaxungu时间:2022-10-02 23:21:43分类:web开发

如何改变input的style属性?
<script language= "javascript ">
function change(){
。。。。。
}
</script>
<input id= "aa " type= "text " value= "microsoft " />
<input id= "bb " type= "button " value= "change " onClick= "change() ">
我想通过点击按钮,修改aa的style为style= "background-color:#CCCCCC "。
能不能不用form定义?


------解决方案--------------------
aa.style.backgroundColor = "#CCCCCC "
------解决方案--------------------
<script language= "javascript ">
function change(){
var aa=document.getElementById( 'aa ');
aa.style.backgroundColor = "#CCCCCC "
}
</script>
<input id= "aa " type= "text " value= "microsoft " />
<input id= "bb " type= "button " value= "change " onClick= "change() ">