0

我需要通过页面中的按钮启动的 javascript 函数执行预定义的 Google 搜索。

所以我之前尝试过没有成功:

<html>
<head>
<script language="JavaScript">     
  function googleSearch(quest){
   var googlefind = "http://www.google.com/search?hl=en&q=" + quest + " buy Blu-Ray DVD";
   window.open(googlefind);
  }
</script>
</head>

<body>
 <INPUT type="button" value="Buy this Anime Now!" onclick="googleSearch("Fullmetal Alchemist Brotherhood");">
</body>
</html>

有人可以帮助我吗?

4

3 回答 3

2

添加escape()googlefind您的函数中,并将关键字更改为在您的onclick.

<html>
<head>
<script language="JavaScript">
 function googleSearch(quest){
  var googlefind = quest + " buy Blu-Ray DVD";
  window.open("http://www.google.com/search?hl=en&q=" + escape(googlefind));
 }
</script>
</head>

<body>
 <INPUT type="button" value="Buy this Anime Now!" onclick="googleSearch('Fullmetal Alchemist Brotherhood');">
</body>
</html>
于 2012-04-30T14:34:13.957 回答
0

另外,请记住,某些浏览器不会像script当前定义的那样喜欢标签。我会改为type='text/javascript而不是language='JavaScript'像下面这样:

<html>
<head>
<script type="text/javascript">
 function googleSearch(quest){
  var googlefind = quest + " buy Blu-Ray DVD";
  window.open("http://www.google.com/search?hl=en&q=" + googlefind);
 }
</script>
</head>

<body>
 <INPUT type="button" value="Buy this Anime Now!" onclick="googleSearch('Fullmetal Alchemist Brotherhood');" />
</body>
</html>
于 2012-04-30T14:40:22.447 回答
0

将传递参数中的双引号替换为单引号 onclick="googleSearch('Fullmetal Alchemist Brotherhood')

于 2012-04-30T14:43:36.083 回答