i want to change the background color after clicking?

后端 未结 5 1298
礼貌的吻别
礼貌的吻别 2021-01-21 18:18

I want to change the background color after clicking

This is my HTML code

...
相关标签:
5条回答
  • 2021-01-21 18:45

    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 讨论(0)
  • 2021-01-21 18:46

    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';
    }
    
    0 讨论(0)
  • 2021-01-21 18:47
    <script language="JavaScript">
    <!--
    function changeBGC(color){
    document.bgColor = color;
    }
    //-->
    </script>
    
    <a href="#" onClick="javascript:changeBGC('#000099')">Click Blue</a>
    
    0 讨论(0)
  • 2021-01-21 18:49

    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)">
    
    0 讨论(0)
  • 2021-01-21 19:11

    Here's the code in jQuery:

    $("td").click(function() {
            $(this).css("background-color","#ABCDEF");
        });
    
    0 讨论(0)
提交回复
热议问题