Rumah > hujung hadapan web > tutorial js > jquery mousedown修改td的样式无效的问题解决

jquery mousedown修改td的样式无效的问题解决

黄舟
Lepaskan: 2017-06-28 09:36:09
asal
1678 orang telah melayarinya

jquery mousedown修改td的样式无效的问题解决

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

//样式

<style type="text/css">

#right td

{

border-right: 1px solid #C1DAD7;

border-bottom: 1px solid #C1DAD7;

font-size: 11px;

padding: 6px 6px 6px 12px;

color: #4f6b72;

font-size: 15px;

}

td.alt

{

background: #F5FAFA;

color: #797268;

}

img

{

max-width: 100px;

max-height: 100px;

}

th

{

border-right: 1px solid #C1DAD7;

border-bottom: 1px solid #C1DAD7;

font-weight: bold;

background: #4a98af;

}

tr.over td

{

background: #ecfbd4; /*这个将是鼠标高亮行的背景色*/

}

td.selected, tr.even td.selected, tr.odd td.selected

{

background: #bce774;

color: #555;

}

tr.click td, td.down

{

background: #bce774;

color: #fff;

}

#right a

{

text-decoration: none;

color: #057fac;

}

#right a:hover

{

text-decoration: none;

color: #999;

}

</style>

 

//脚本

<script type="text/javascript">

$(document).ready(function(){

$("#Clothes tr td").mousedown(function(){//鼠标按住时remove mouseenter时 td的样式。

$(this).removeClass("over");$(this).addClass("click");})

$("#Clothes tr td").mouseup(function(){//鼠标弹起时,清除td的样式

$(this).removeClass("click");})

$("#Clothes tr").mouseenter(function(){//鼠标进入tr添加样式.over

$(this).addClass("over");})

$("#Clothes tr").mouseout(function(){ //鼠标离开tr,清除样式.over

$(this).removeClass("over");})

$("#Clothes tr").click(function(){ //click tr时,添加样式.click

$(this).addClass("click");$(this).siblings().removeClass("click");})

});

</script>

 

<table id="Clothes">

<tr>

<td style="width: 10%">

<td style="width: 20%">

<td style="width: 10%">

</tr>

</table>

Salin selepas log masuk

最佳答案:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

<style type="text/css">

        #right td

        {

            border-right: 1px solid #C1DAD7;

            border-bottom: 1px solid #C1DAD7;

            font-size: 11px;

            padding: 6px 6px 6px 12px;

            color: #4f6b72;

            font-size: 15px;

        }

        td.alt

        {

            background: #F5FAFA;

            color: #797268;

        }

        img

        {

            max-width: 100px;

            max-height: 100px;

        }

        th

        {

            border-right: 1px solid #C1DAD7;

            border-bottom: 1px solid #C1DAD7;

            font-weight: bold;

            background: #4a98af;

        }

        tr.over td

        {

            background: #ecfbd4; /*这个将是鼠标高亮行的背景色*/

        }

        td.selected, tr.even td.selected, tr.odd td.selected

        {

            background: #bce774;

            color: #555;

        }

        tr.click td, td.down

        {

            background: #bce774;

            color: #fff;

        }

        #right a

        {

            text-decoration: none;

            color: #057fac;

        }

        #right a:hover

        {

            text-decoration: none;

            color: #999;

        }

    </style>

<script type="text/javascript">

        $(document).ready(function () {

            $("#right tr td").mousedown(function () {//鼠标按住时remove mouseenter时 td的样式。

                $(this).removeClass("over"); $(this).addClass("click");

            })

            $("#right tr td").mouseup(function () {//鼠标弹起时,清除td的样式

                $(this).removeClass("click");

            })

            $("#right tr").mouseenter(function () {//鼠标进入tr添加样式.over

                $(this).addClass("over");

            })

            $("#right tr").mouseout(function () {  //鼠标离开tr,清除样式.over

                $(this).removeClass("over");

            })

            $("#right tr").click(function () {  //click tr时,添加样式.click

                $(this).addClass("click"); $(this).siblings().removeClass("click");

            })

        });

    </script>

  

<body>

    <table id="right">

        <tr>

            <td style="width: 10%">哈哈

            </td>

            <td style="width: 20%">嘿嘿

            </td>

            <td style="width: 10%">呵呵

            </td>

        </tr>

    </table>

</body>

Salin selepas log masuk

本来你写的是正确的,但是你table里没有数据,所以刚加载页面的时候就什么也不显示,所以你得里面写数据,还有就是你整个样式都是基于right,但是你却在table里写的是Clothes,自己好好看看改改吧

Atas ialah kandungan terperinci jquery mousedown修改td的样式无效的问题解决. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan