English 中文(简体)
如何在投入“:重点”时改变表流的背景色?
原标题:How to change background color of table row (tr) when input is ":focus"?
  • 时间:2011-05-13 02:05:52
  •  标签:
  • css

My HTML: <tr><td>Text</td><td><input type="text" value=""></td></tr>

My CSS: input:focus tr{ background-color:#fff;}

在我撰写投入领域的文本时,我要强调一行。 我知道在“投入”之前是“减”的,但这样做是可能的。

Thanks a bunch

最佳回答

可悲的是,无。 见。 CSS 在职儿童父母的选定人

http://jsfiddle.net

问题回答

利用JQuery非常可能。 观察:

<><><><>>><>>>>><>>>>>>

<table border="1" cellpadding="20">
    <tr>
        <td>Text</td>
        <td height="50" width="100" id="somename"><input type="text" value="" id="mirza"></td>
    </tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>a&nbsp;</td><td>1&nbsp;</td></tr>
    <tr><td>a&nbsp;</td><td>1&nbsp;</td></tr>
    <tr><td>a&nbsp;</td><td>1&nbsp;</td></tr>
    <tr><td>a&nbsp;</td><td>1&nbsp;</td></tr>
    <tr><td>a&nbsp;</td><td>1&nbsp;</td></tr>
</table>

CSS

.highlightedRow { background-color: orange; }

Jquery

$( input ).focus(function() {
    $(this).parent().parent().addClass( highlightedRow );
});

$( input ).blur(function() {
    $(this).parent().parent().removeClass( highlightedRow );
});

令人痛心的是,没有办法将母子同心协力,因此你不得不使用 j。

This is good for when you are generating a lot of similar rows (looping through large datasets, etc): Script:

function rowSet(data_id){
    document.getElementById( row_  + data_id).style.backgroundColor =  blue ;
}
function rowReset(data_id){
    document.getElementById( row_  + data_id).style.backgroundColor =   ;
}

机构:

<body>
    <form>
        <table>
            <tr id="row_#data_id#">
                <td><input name="input1_#data_id#" onFocus="rowSet(#data_id#);" onBlur="rowReset(#data_id#);"></td>
                <td><input name="input2_#data_id#" onFocus="rowSet(#data_id#);" onBlur="rowReset(#data_id#);"></td>
            </tr>
        </table>
    </form>
</body>

你们也可以使用“目前”或你喜欢的任何东西。

这一分类法应当做到:

$( input ).focus(function() {
    $( tr ).css("background-color", "#c00");
});

Demo rel=“nofollow>here





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签