且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在我指定的div宽度和高度中包含google搜索结果?

更新时间:2022-11-02 14:15:00

这是我尝试过的示例.试试这个.

This is a sample which I have tried. try this.

<head>
<title>Search</title>

<style>
    #searchcontrol
    {
        margin-LEFT:500PX;
    }
</style>

<script src="https://www.google.com/jsapi" type="text/javascript"></script>

<script language="Javascript" type="text/javascript">
    //<!
    google.load('search', '1');
    function DoSearch() 
    {
        // Create a search control
        var searchControl = new google.search.SearchControl();
        searchControl.addSearcher(new google.search.WebSearch());

        searchControl.draw(document.getElementById("searchcontrol"));

        // execute an inital search
        searchControl.execute(document.getElementById("secrchBox").value);
    }
    //]]>
</script>
</head>
<body>
    <div id="searchcontrol">
        <input type="text" id="secrchBox"/>
        <input type="button" value="Submit" onclick=" DoSearch()"/>
    </div>
</body>
</html>

编辑

<head>
<title>Search</title>
<style>
    #searchcontrol
    {
        margin-LEFT:500PX;
    }
</style>

<script src="https://www.google.com/jsapi" type="text/javascript"></script>

<script language="Javascript" type="text/javascript">
    //<!
    google.load("search", "1", { "nocss": true });

    function DoSearch() 
    {
        var ss = document.getElementById("secrchBox").value;
        // Create a search control
        var searchControl = new google.search.SearchControl();

        searchControl.addSearcher(new google.search.WebSearch());

        searchControl.draw(document.getElementById("searchcontrol"));

        // execute an inital search
        searchControl.execute(ss);
    }
    //]]>
</script>
</head>
<body>
    <div id="searchcontrol">
        <input type="text" id="secrchBox"/>
        <input type="button" value="Submit" onclick=" DoSearch()"/>
    </div>
</body>
</html> 

现在将不加载默认的css.您可以根据需要进行自定义.

Now default css will not load. You can customize as your wish.