添加一个 onclick 函数来转到 JavaScript 中的 url?

2022-08-30 04:51:56

我正在使用这个花哨的小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>

答案 1

尝试

 window.location = url;

也可使用

 window.open(url);

如果您想在新窗口中打开。


答案 2

只需使用这个

onclick="location.href='pageurl.html';"