如何通过单击第一个div值在第二个div中显示一个div值

时间:2013-02-18 06:55:24

标签: javascript html ajax

这是我的HTML代码:

<html>
</head>
<body>
       <div id="link">
       <a href="http://www.google.com">google</a>
       </div>
       <div id="result"></div>
</body>
</html>
</html>

我想输出这样的东西
点击谷歌,然后在那里显示其他div

感谢

4 个答案:

答案 0 :(得分:1)

尝试下面的javascript代码

var el=document.getElementById("result");
el.innerHTML="<iframe src=\'http://www.google.com\'></iframe>";

答案 1 :(得分:0)

试试吧...... Google Web Search API

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

    google.load('search', '1');

    $('a').live('click',function OnLoad() {
      // Create a search control
      var searchControl = new google.search.SearchControl();

      // Add in a full set of searchers
      var localSearch = new google.search.LocalSearch();
      searchControl.addSearcher(localSearch);
      searchControl.addSearcher(new google.search.WebSearch());
      searchControl.addSearcher(new google.search.VideoSearch());
      searchControl.addSearcher(new google.search.BlogSearch());
      searchControl.addSearcher(new google.search.NewsSearch());
      searchControl.addSearcher(new google.search.ImageSearch());
      searchControl.addSearcher(new google.search.BookSearch());
      searchControl.addSearcher(new google.search.PatentSearch());

      // Set the Local Search center point
      localSearch.setCenterPoint("New York, NY");

      // tell the searcher to draw itself and tell it where to attach
      searchControl.draw(document.getElementById("searchcontrol"));

      // execute an inital search
      searchControl.execute("VW GTI");
    }
    google.setOnLoadCallback(OnLoad);

    </script>

答案 2 :(得分:0)

执行此操作的最佳方法是制作2个不同的网页(您的初始页面和结果),然后在iframe中填充它们。您可以在此处查看演示:LINK

答案 3 :(得分:0)

试试这项工作......

首先创建一个PHP文件: -

<?php
$ch = curl_init($_POST['action']);
curl_setopt($ch, CURLOPT_POST, FALSE);
//curl_setopt($ch, CURLOPT_URL, $r->event_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($ch);
curl_close($ch);
echo $html;
?>
  1. javascript代码: -

    function result(url)
    { $.ajax({ url: 'one.php',
    data: {action: url},
    type: 'post',
    success: function(output) {
    $('#result').html(output);
    }
    });
    }

  2. 3.code for your html file:-

       <body>
           <div id="link">
             <a href="javascript:void(0)" onclick="result('https://www.google.co.in/')">google</a>
           </div>
            <div id="result" height="200" width="200"></div>
      </body>