Simple JavaScript search box

后端 未结 3 1401
走了就别回头了
走了就别回头了 2021-02-10 14:49

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

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

提交回复
热议问题