특정 표의 영역을 가리킬 때 텍스트에 밑줄을 표시하고 싶습니다.
여기 내 코드는 작동하지만, 유일의 1 달러의 두 번째 멀리 다음 밑줄 페이드도 커서 (모두 시도 테이블 내부에 불구 go
하고 foo
시험에) :
JS :
<script>
$(document).ready(function(){
$(function(){
$('.foo').mouseenter(function(){
$(".vvv").addClass('altbg')
}).mouseout(function(){
$(".vvv").removeClass('altbg')
});
});
})
</script>
CSS :
.altbg {
text-decoration:underline;
}
HTML :
<div class="go">
<table border="1" class="foo">
<col style="width:115px;" />
<col style="width:280px;" />
<col style="width:125px;" />
<col style="width:145px;" />
<col style="width:125px;" />
<col style="width:230px;" />
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr></table>
</div>
<div class="vvv">Hello</div>
편집 : 두 번째 관련 질문 :
색상이 이미 ID로 정의되어 있더라도 표를 가리키면 텍스트 색상이 변경되기를 원합니다.
ID를 클래스로 변경하는 것 외에도이 div를 색상으로 변경하려면 어떻게해야합니까?
선택자에 클래스를 지정하기 위해 스크립트의 내용을 변경해야 할 수도 있지만 어떻게해야할지 모르겠습니다.
JS :
<script>
$(document).ready(function(){
$(function(){
$('td').mouseenter(function(){
$(".vvv").addClass('altbg')
}).mouseout(function(){
$(".vvv").removeClass('altbg')
});
});
})
</script>
CSS :
#meh {color:red}
.altbg {
text-decoration:underline;
color:blue;
}
HTML :
<div class="go">
<table border="1" class="foo">
<col style="width:115px;" />
<col style="width:280px;" />
<col style="width:125px;" />
<col style="width:145px;" />
<col style="width:125px;" />
<col style="width:230px;" />
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr></table>
</div>
<div id="meh" class="vvv">Hello</div>
호버링 시간이 아니라 마우스가 더 이상 나타나지 않는 위치입니다. 어떤 이유로 table
의 클래스를 대상으로하는 것은 작동하지 않습니다. 대신 그 td
안에 있는 요소 를 대상 으로 지정해야합니다.
$(document).ready(function () {
$(function () {
$('td').mouseenter(function () {
$(".vvv").addClass('altbg')
}).mouseout(function () {
$(".vvv").removeClass('altbg')
});
});
})
.altbg {
text-decoration:underline;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="go">
<table border="1" class="foo">
<col style="width:115px;" />
<col style="width:280px;" />
<col style="width:125px;" />
<col style="width:145px;" />
<col style="width:125px;" />
<col style="width:230px;" />
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>
</div>
<div class="vvv">Hello</div>
여기 jsfiddle 데모가 있습니다 : http://jsfiddle.net/0uqboeat/ too.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다