2012-04-30 11 views
0

ページ内のボタンで起動されたjavascript関数を使用して、事前定義済みのGoogle検索を実行する必要があります。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> 

ください助けることができていますか?

答えて

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> 
+0

にパラメータ を渡すことに問題、フェルナンドを単一引用符で二重引用符を置き換え、さあなたの二重引用符http://jsfiddle.net/ZLQ3P/ –

+0

助けてくれてありがとう! –

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> 
+0

私はそれを得ました、それは別の良いサンプルです、ありがとう。 –

0

はonclickの= "Google検索(『鋼の錬金術師同胞団』)

関連する問題