Adding an onclick function to go to url in JavaScript?

前端 未结 9 1223
北荒
北荒 2020-11-29 18:28

I am using this fancy little JavaScript to highlight a field as the user hovers over it. Could you please tell me if there is a way of adding an onclick functio

相关标签:
9条回答
  • 2020-11-29 18:58

    try

    location = url;
    

    function url() {
        location = 'https://example.com';
    }
    <input type="button" value="Inline" 
    onclick="location='https://example.com'" />
    
    <input type="button" value="URL()" 
    onclick="url()" />

    0 讨论(0)
  • 2020-11-29 19:00

    If you would like to open link in a new tab, you can:

    $("a#thing_to_click").on('click',function(){
        window.open('https://yoururl.com', '_blank');
    });
    
    0 讨论(0)
  • 2020-11-29 19:03
    function URL() {
        location.href = 'http://your.url.here';
    }
    
    0 讨论(0)
提交回复
热议问题