比如一个<p>标签的背景色。现在想实现点击这个<p>标签的时候如果背景是红色的话那么变成蓝色,如果是蓝色的就变成红色。新手嘛,大家见谅。呵呵 $("p.menu_head").click(function()
{
囧囧囧囧囧囧囧囧囧囧囧囧囧 if(囧囧囧囧囧囧囧囧囧囧囧){
$(this).css({background:"red"});
}else{
$(this).css({background:"#000"});
}
});
{
囧囧囧囧囧囧囧囧囧囧囧囧囧 if(囧囧囧囧囧囧囧囧囧囧囧){
$(this).css({background:"red"});
}else{
$(this).css({background:"#000"});
}
});
解决方案 »
- webQQ网页的相关制作,求助!急!!!
- 别人网站的javascript代码,我怎么样才能看到?
- 如何用Javascript实现带复选框的下拉列表框
- 想实现这样一个效果
- 如何自动决定 focus 的 textbox?
- javascript如何引用不定名表单?
- 如何去掉prompt命令弹出对话框中的“JavaScript提示:”字符串??
- 不同的按钮提交到同一个页面但参数不同
- JavaScript该怎样处理有换行的文件?急!
- ExtJs拖拽一个Panel时,如何以复制的形式拖拽?
- mootools1.2中 remote 函数中的CallFunction
- ExtJs 中 如何让 form 显示为两列
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.js"></script>
<script type="text/javascript">
$(function(){
$('p').toggle(function(){
$(this).css('backgroundColor','red');
},function(){
$(this).css('backgroundColor','blue');
});
});
</script>
</head>
<body>
<p>我在这里</p>
</body>
</html>
<!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 type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$("p.menu_head").click( function() {
if ($(this).hasClass("bgRed")) $(this).removeClass("bgRed").addClass("bgBlue");
else $(this).removeClass("bgBlue").addClass("bgRed");
});
});
</script>
<style type="text/css">
p.bgRed { background-color:red; }
p.bgBlue { background-color:blue; }
</style>
</head><body>
<p class="menu_head bgRed">test</p>
</body>
</html>