我这里有一些代码:
<html>
<script type="text/javascript">
document.getElementById('myElement').onclick = function ()
{
var searchterm = document.getElementById('bereich').value;
document.href("http://www.google.com/serach?q=" + searchterm);
}
</script>
<body>
<center>
<img src="https://www.google.de/images/srpr/logo3w.png"><br>
<input type="text" name="q"> <input type="button" value="Search" onclick="startSearch()">
</center>
这是行不通的。我知道这根本就是一个菜鸟,但我不知道 javascript。任何人都可以帮助我吗?
添加:
我也试过:
<html>
<body>
<center>
<img src="https://www.google.de/images/srpr/logo3w.png"><br>
<input type="text" name="q"> <input type="button" value="Search" onclick="startSearch()">
</center>
<script type="text/javascript">
window.onload = function(){
document.getElementById('myElement').onclick = function ()
{
var searchterm = document.getElementById('bereich').value;
document.href = "http://www.google.com/serach?q=" + searchterm;
}
};
和:
<html>
<body>
<center>
<img src="https://www.google.de/images/srpr/logo3w.png"><br>
<input type="text" name="q"> <input type="button" value="Search" name="searchButton" onclick="startSearch()">
</center>
<script type="text/javascript">
function triggerGoogleSearch()
{
var searchterm = document.getElementById('bereich').value;
document.href("http://www.google.com/serach?q=" + searchterm);
}
document.getElementById('searchButton').onclick = triggerGoogleSearch();
</script>
</body>
</html>