我创建了一个工具,通过在多个站点的新窗口中的URL中插入值,使我的工作更容易一些。它工作得很好,但现在我遇到了提交时清除搜索值的问题。 使用Javascript:
<script language="JAVASCRIPT">
function run() {
var request = document.text.query.value;
var req = "";
var endofurl = "endofurl.html";
for(var i = 0; i < request.length; i++) {
var ch;
if((ch = request.substring(i, i + 1)) == " ") req += " ";
else req += ch;
}
if(document.search.website.checked) {
var website = open( "https://www.website.com/" + req, "website");
}
//--></script>
HTML:
<form name="search">
Please select the networks you want to use.
<p>
</center>
</p>
<div class="row">
<div class="column">
<br>
<input name="website" type="checkbox">Website to Search
<form name="text" onsubmit="run(); return false;">
<center>And enter your Query.</center>
<center>
<input name="query" placeholder="Steropodon" value="" size="50" type="TEXT">
<input value="Search" onclick="run()" type="BUTTON">
</center>
到目前为止,return false一直在努力将输入值保存在form =“text”输入名称=“查询”中,但现在它似乎清除它并重新加载页面。我不确定是什么改变了。
答案 0 :(得分:0)
您的代码在打开和关闭代码时出错。
试试这段代码。它有效:
<html>
<head></head>
<body>
Please select the networks you want to use
<div class="row">
<div class="column">
<br>
<input name="website" type="checkbox">Website to Search
<form name="text" onsubmit="run(); return false;">
<center>And enter your Query.</center>
<center>
<input name="query" placeholder="Steropodon" value="" size="50" type="TEXT">
<input value="Search" onclick="run()" type="BUTTON">
</center>
</form>
</div>
</div>
<script language="JAVASCRIPT">
function run() {
var request = document.text.query.value;
var req = "";
var endofurl = "endofurl.html";
for(var i = 0; i < request.length; i++) {
var ch;
if((ch = request.substring(i, i + 1)) == " ") req += " ";
else req += ch;
}
var checkbox = document.getElementsByName("website");
if(checkbox[0].checked) {
var website = open("https://www.website.com/" + req,
"website");
}
}
</script>
</body>
</html>
希望它有所帮助。
答案 1 :(得分:0)
我修好了。这不是标签。我只粘贴了一小部分总代码,以便更容易阅读,但我没有让它更容易阅读。问题是未定义的输入。我一直在添加许多if语句但没有相应的复选框。哎呀。
感谢您的帮助。