开发者

i want to change the background color after clicking?

I want to change the backgr开发者_开发知识库ound color after clicking

This is my HTML code

<td class="meun" onclick="getclick();">...</td>

And this is my JavaScript:

function getclick()
{
    this.style.background-color: #EFF2F7;
}

http://jsfiddle.net/3ZmCh/

i want when click any on in the td in the table to change it's background color


http://jsfiddle.net/ThiefMaster/3ZmCh/16/

You need to pass this as an argument and use proper JavaScript in the handler method:

function getclick(elem) {
    elem.style.backgroundColor = '#EFF2F7';
}


Your getclick() function should look like this:

function getclick(el)
{
    el.style.backgroundColor='#888888';
}

In js, styles look a little different

and in your td, do

<td onclick="getclick(this)">


Here's the code in jQuery:

$("td").click(function() {
        $(this).css("background-color","#ABCDEF");
    });


<script language="JavaScript">
<!--
function changeBGC(color){
document.bgColor = color;
}
//-->
</script>

<a href="#" onClick="javascript:changeBGC('#000099')">Click Blue</a>


I would add the id to your <td> tag and change the name of function for a better understanding.

function changeBgColor() {

var tableData = document.getElementById('meun');

tableData.style.backgroundColor = '#EFF2F7';

}




<td id='meun' class="meun" onclick="changeBgColor()">...</td>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜