Simple JavaScript search box

后端 未结 3 578
遇见更好的自我
遇见更好的自我 2021-02-10 14:30

I tried connecting the first text box, so it would turn it into a URL, and then when \'search\' is clicked, it would jump to that website, not sure if it\'s impossible, or i\'m

3条回答
  •  逝去的感伤
    2021-02-10 15:14

    Try this JavaScript:

    function goTo()
    {
        location.href = document.getElementById('link_id').value;
    }
    

    and change the onclick in the HTML:

    
    
    

    Edit:

    If you want to follow the unobtrusive JavaScript way, you would move the onclick completely into your JavaScript code, and remove it in the HTML:

    document.getElementById('link').onclick = function()
    {
        location.href = document.getElementById('link_id').value;
    };
    

提交回复
热议问题