2011-05-13 14 views

cevap

1

, CSS ile ana elemanı stil yolu yok, bu yüzden javascript kullanmak gerekecek.

-1

Bu jquery kodu yapmalı:

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

Demo here

+0

Bkz: http://jsfiddle.net/9mR95/ Bu kod, yalnızca biri seçildiğinde giriş öğesinin ebeveyni değil, tüm satırları vurgulayacak ve bulanıklaştırmadan sonra satırı hükümsüz kılacaktır. – Ryan

1

Bu, bir ürettiğini zaman için iyidir Benzer satırların çokluğu (büyük veri kümeleriyle döngü, vb.): Komut Dosyası:

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

Gövde:

<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> 

Ayrıca currentRow kullanabilirsiniz, ya da ne tercih ederim.

5

JQuery'yi kullanarak, bu çok mümkündür. Gözlemleyin:

HTML

<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'); 
}); 
+0

+1 çünkü bu ve alternatif ve benim için çalıştı. –

İlgili konular