Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
加载页面的Javascript不工作_Javascript - Fatal编程技术网

加载页面的Javascript不工作

加载页面的Javascript不工作,javascript,Javascript,我试图从文本输入中获取文本,将其附加到URL,然后使用Javascript转到该URL。但当我提交时,它似乎只是重新加载页面 家 函数loadSearchResult(searchToLoad){ window.location=”https://encrypted.google.com/search?q=“+搜索加载; } 搜寻 您需要在提交函数中使用event.preventDefault() 此外,由于很多原因,内联js(html中的onsubmit)是一种不好的做法。以下是一些:

我试图从文本输入中获取文本,将其附加到URL,然后使用Javascript转到该URL。但当我提交时,它似乎只是重新加载页面


家
函数loadSearchResult(searchToLoad){
window.location=”https://encrypted.google.com/search?q=“+搜索加载;
}
搜寻

您需要在提交函数中使用
event.preventDefault()

此外,由于很多原因,内联js(html中的onsubmit)是一种不好的做法。以下是一些:

最好使用javascript获取对表单的引用并附加事件侦听器

<form id="myForm">
  <input type="submit" value="Submit">
</form>

您需要在提交函数中使用
event.preventDefault()

此外,由于很多原因,内联js(html中的onsubmit)是一种不好的做法。以下是一些:

最好使用javascript获取对表单的引用并附加事件侦听器

<form id="myForm">
  <input type="submit" value="Submit">
</form>

您需要防止
onsubmit
的默认行为
您可以使用
返回false

<html>
    <head>
        <title>Home</title>
        <link rel="stylesheet" href="main.css" />
        <script type="text/javascript">
            function loadSearchResult(searchToLoad) {
                window.location = "https://encrypted.google.com/search?q=" + searchToLoad;
                return false;
            }
        </script>
    </head>
    <body>
        <form onsubmit="return loadSearchResult(document.getElementById('googleBox').value)" method="post">
            <fieldset>
                <legend>Search</legend>
                <input type="text" id="googleBox">
            </fieldset>
        </form>
    </body>
</html>

家
函数loadSearchResult(searchToLoad){
window.location=”https://encrypted.google.com/search?q=“+搜索加载;
返回false;
}
搜寻

您需要防止
onsubmit的默认行为

您可以使用
返回false

<html>
    <head>
        <title>Home</title>
        <link rel="stylesheet" href="main.css" />
        <script type="text/javascript">
            function loadSearchResult(searchToLoad) {
                window.location = "https://encrypted.google.com/search?q=" + searchToLoad;
                return false;
            }
        </script>
    </head>
    <body>
        <form onsubmit="return loadSearchResult(document.getElementById('googleBox').value)" method="post">
            <fieldset>
                <legend>Search</legend>
                <input type="text" id="googleBox">
            </fieldset>
        </form>
    </body>
</html>

家
函数loadSearchResult(searchToLoad){
window.location=”https://encrypted.google.com/search?q=“+搜索加载;
返回false;
}
搜寻