ユーザーがフィールドにカーソルを置くと、そのフィールドがハイライトされるという、ちょっとおしゃれなJavaScriptを使っています。リンクとして動作し、URLに移動するonclick
関数を追加する方法があれば、教えていただけますか?
<script>
$(function() {
$('tr').hover(function() {
$(this).css('background-color', '#eee');
$(this).contents('td').css({'border': '0px solid red', 'border-left': 'none', 'border-right': 'none'});
$(this).contents('td:first').css('border-left', '0px solid red');
$(this).contents('td:last').css('border-right', '0px solid red');
},
function() {
$(this).css('background-color', '#FFFFFF');
$(this).contents('td').css('border', 'none');
$('a#read_message.php').click(function(){ URL(); });
});
});
</script>
jqueryでユーザーを別のURLに送るには、次のようにします。
$("a#thing_to_click").on('click', function(){
window.location = "http://www.google.com/";
});
この方法でも動作しますが、最近では上記の方法がより新しい正しい方法となっています。
$("a#thing_to_click").click(function(e){
e.preventDefault();
window.location = "http://www.google.com/";
});