javascript input改变css的样式

javascript input改变css的样式使用的语法如下:document.getElementById(id).style.property=new style例如:Hello World! document.getElementById("p2").style.color="blue"; 备注:JS改变元素属性的方法如下: var div = document.getElementByIdx_x('d1'); div.setAttribute("class", "abc");...
javascript input改变css的样式
javascript是吧,绑个事件
如:<input type='text' id='abc' onfocus='getfocus()' onblur='lostfocus()' />

js代码:
function getfocus(){
document.getElementById("abc").className = "input_one_bg";
}
function lostfocus{
document.getElementById("abc").className = "input_bg";
}

jQuery简单一点
$(document).ready(function(){
$("#abc").focus(function(){
$(this).Class("input_one_bg");

})

$("#abc").blur(function(){
$(this).Class("input_bg");

})
})

之前的class名搞错了,已对调2013-06-06
$("input").focus(function(){ $("input").css("background-image","路径");});$("input").blur(function(){ $("input").css("background-image","路径");});2013-06-06
javascript input改变css的样式使用的语法如下:
document.getElementById(id).style.property=new style例如:
<p id="p2">Hello World!</p> <script> document.getElementById("p2").style.color="blue"; </script>备注:JS改变元素属性的方法如下:
<script> var div = document.getElementByIdx_x('d1'); div.setAttribute("class", "abc"); </script>2015-07-11
给它一个聚焦和离焦的事件,聚焦的时候,使用.input_bg 样式,blur时,使用.input_one_bg样式2013-06-06
Vue实践-CSS样式position/display/float属性对比使用

2020-12-25
mengvlog 阅读 11 次 更新于 2025-06-19 22:40:56 我来答关注问题0
檬味博客在线解答立即免费咨询

CSS相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部