js控制所有页面内<input type="text">的样式 js控制所有页面内<input type="text">的样式希望可以实现的效果是 点击页面内的某个<input type="text">的控件时 控件背景颜色改变就是onfocus时 textbox背景颜色改变 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 [code=JScript] $(document).ready(function() { $('input').click(function() { this.css('background-color', '#f0f0f0'); }); $('input').blur(function() { this.css('background-color', ''); }); });[/code 试试这个看<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script type="text/javascript">function fnInitInputFocus(){ var _oInputs = document.getElementsByTagName("input"); for (var i=0; i<_oInputs.length; i++) { if (_oInputs[i].type == "text") { _oInputs[i].onfocus = function() { this.style.backgroundColor = "#0000ff"; } _oInputs[i].onblur = function() { this.style.backgroundColor = ""; } } }}function Main(){ fnInitInputFocus();}</script></head><body onload="Main()"><form> <input name="tagV1" type="text" /><br /> <input name="tagV2" type="text" /><br /> <input name="tagV3" type="text" /><br /> <input type="submit" value="submit" /></form></body></html> 在js里面设定样式即可document.getElementById("youput").style.backgroundColor = ""; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script language="javascript" src="js/jquery-1.3.2.min.js"></script></head><body><input type="text" style="background-color:yellow"/></body></html><script language="javascript">$(function(){ $('input[type=text]').focus(textFocus); $('input[type=text]').blur(textBlur);});function textFocus(){ $(this).css('background-color', 'green');}function textBlur(){ $(this).css('background-color', 'yellow');}</script> this是dom对象,不是jquery对象,$(this)才是jquery对象,才可以引用css方法 新人,来学习学习。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title><script type="text/javascript">var oldInput;function go(){ try{oldInput.style.backgroundColor = "";}catch(e){} var oEle = event.srcElement; oldInput = oEle; if((oEle.tagName.toLowerCase()=="input") && (oEle.type.toLowerCase()=="text")) oEle.style.backgroundColor = "red";}</script></head><body onClick="go();"><form> <input name="tagV1" type="text" /><br /> <input name="tagV2" type="text" /><br /> <input name="tagV3" type="text" /><br /> <input type="submit" value="submit" /></form></body></html> IE浏览器设置div display:none 失效 jquery是什么东东 求教iChat 类似excel合并单元格的js 表单中提交过来的编码过的中文,如何在javascript中还原成中文呢? 关于正则式,请大侠相助??? 一个下拉菜单的问题. QQ秀试穿衣服怎么做? 求助!!!急需解决! 那有javascript 或者html /dhtml的开手人员参考手册。 在M$的网点上有html/dhtml的reference 但还像没有下载,只能在行查询(不方便)。 js绑定istbox 关于document.all.tags
$(document).ready(function() {
$('input').click(function() {
this.css('background-color', '#f0f0f0');
});
$('input').blur(function() {
this.css('background-color', '');
});
});
[/code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function fnInitInputFocus()
{
var _oInputs = document.getElementsByTagName("input");
for (var i=0; i<_oInputs.length; i++)
{
if (_oInputs[i].type == "text")
{
_oInputs[i].onfocus = function()
{
this.style.backgroundColor = "#0000ff";
}
_oInputs[i].onblur = function()
{
this.style.backgroundColor = "";
}
}
}
}
function Main()
{
fnInitInputFocus();
}
</script>
</head><body onload="Main()">
<form>
<input name="tagV1" type="text" /><br />
<input name="tagV2" type="text" /><br />
<input name="tagV3" type="text" /><br />
<input type="submit" value="submit" />
</form>
</body>
</html>
document.getElementById("youput").style.backgroundColor = "";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript" src="js/jquery-1.3.2.min.js"></script>
</head>
<body>
<input type="text" style="background-color:yellow"/>
</body>
</html>
<script language="javascript">
$(function()
{
$('input[type=text]').focus(textFocus);
$('input[type=text]').blur(textBlur);
});
function textFocus()
{
$(this).css('background-color', 'green');
}
function textBlur()
{
$(this).css('background-color', 'yellow');
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var oldInput;
function go()
{
try{oldInput.style.backgroundColor = "";}catch(e){}
var oEle = event.srcElement;
oldInput = oEle;
if((oEle.tagName.toLowerCase()=="input") && (oEle.type.toLowerCase()=="text"))
oEle.style.backgroundColor = "red";
}
</script>
</head><body onClick="go();">
<form>
<input name="tagV1" type="text" /><br />
<input name="tagV2" type="text" /><br />
<input name="tagV3" type="text" /><br />
<input type="submit" value="submit" />
</form>
</body>
</html>