gpt4 book ai didi

javascript - 在不破坏我的代码的情况下删除函数

转载 作者:行者123 更新时间:2023-11-30 06:16:03 24 4
gpt4 key购买 nike

我正在尝试在我的网络应用程序上实现站点搜索功能,但我想删除冗余的单选按钮输入。

原始代码允许您使用三个单选按钮选择搜索引擎。我已经删除了三个按钮,但我不知道如何删除最后一个。我只想默认使用 google。

// All-in-one Internal Site Search script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use

//Enter domain of site to search.
var domainroot = "ts.xxxxxxx.net"

var searchaction = [ //form action for the 3 search engines
"http://www.google.com/search"

]

var queryfieldname = ["q", "p", "q"] //name of hidden query form for the 3 search engines

function switchaction(cur, index) {
cur.form.action = searchaction[index]
document.getElementById("hiddenquery").name = queryfieldname[index]
}

function jksitesearch(curobj) {
for (i = 0; i < document.jksearch.se.length; i++) { //loop through radio to see which is checked
if (document.jksearch.se[i].checked == true)
switchaction(document.jksearch.se[i], i)
}
document.getElementById("hiddenquery").value = "site:" + domainroot + " " + curobj.qfront.value
}
<form name="jksearch" action="http://www.google.com/search" method="get" onSubmit="jksitesearch(this)">


<input id="hiddenquery" type="hidden" name="q" />
<input name="qfront" type="text" style="width: 200px" value="" /> <input type="submit" value="Search" /><br />
<div style="font: bold 11px Verdana;"><input name="se" type="radio" checked>
</div>


</form>

最佳答案

您可以使用输入 type='hidden' 并设置 value='1' 来获得相同的结果。

如果出于某种原因必须在表单中保留单选按钮,请在输入的父节点上设置display:none;

// All-in-one Internal Site Search script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use

//Enter domain of site to search.
var domainroot = "ts.kiwiroad.net"

var searchaction = [ //form action for the 3 search engines
"http://www.google.com/search"

]

var queryfieldname = ["q", "p", "q"] //name of hidden query form for the 3 search engines

function switchaction(cur, index) {
cur.form.action = searchaction[index]
document.getElementById("hiddenquery").name = queryfieldname[index]
}

function jksitesearch(curobj) {
for (i = 0; i < document.jksearch.se.length; i++) { //loop through radio to see which is checked
if (document.jksearch.se[i].checked == true)
switchaction(document.jksearch.se[i], i)
}
document.getElementById("hiddenquery").value = "site:" + domainroot + " " + curobj.qfront.value
}

// console.log(document.querySelector('input[name="se"]').value);
<form name="jksearch" action="http://www.google.com/search" method="get" onSubmit="jksitesearch(this)">
<input id="hiddenquery" type="hidden" name="q" />
<input name="qfront" type="text" style="width: 200px" value="" /> <input type="submit" value="Search" /><br />
<div style="font: bold 11px Verdana;">
<input name="se" type="hidden" value="1">
</div>
</form>

希望对您有所帮助,

关于javascript - 在不破坏我的代码的情况下删除函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56094435/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com