Chrome 再造我感觉幸运按钮

3gtaxfhh  于 2023-09-28  发布在  Go
关注(0)|答案(1)|浏览(79)

我的目标是,当我感觉幸运按钮被按下时,用户被发送到搜索的第一页
我怎么能这么做呢?我在想当按钮被按下时使用一些功能或者有什么更简单的方法吗?

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Search</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body >
        <form class="bar" action="https://www.google.com/search">
            <input class="search" type="text" name="q">
            <input id ="search" type="submit" value="Google Search">
            <input id ="luck" type="button" value="I am feeling lucky">
        </form>
        <ul id="links">
            <li><a href="imagesearch.html">Image Search </a></li>
            <br>
            <li><a href="advancedsearch.html">Advanced Search </a></li>
        </ul>
    </body>
</html>
nwnhqdif

nwnhqdif1#

你可以使用js来做这件事:

function feelingLucky() {
   var query = document.querySelector('.search').value;
   window.location.href = 'https://www.google.com/search?q=' + encodeURIComponent(query) + '&btnI';
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Search</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body >
        <form class="bar" action="https://www.google.com/search">
            <input class="search" type="text" name="q">
            <input id ="search" type="submit" value="Google Search">
            <input id ="luck" type="button" value="I am feeling lucky" onclick="feelingLucky()">
        </form>
        <ul id="links">
            <li><a href="imagesearch.html">Image Search </a></li>
            <br>
            <li><a href="advancedsearch.html">Advanced Search </a></li>
        </ul>
    </body>
</html>

相关问题