如何将 URL 的结尾传递给 Value="";以一种形式 [英] How to pass the end of the URL to a Value="" in a form
问题描述
我的硬盘驱动器上有一个 .htlm 文件,它是我的书籍列表,顶部有一个表单和一个脚本,可以让我搜索文件的内容.我喜欢在浏览时访问这个文件.我使用带有扩展名Advanced URL Builder"的 Firefox,这个扩展允许我突出显示几个词,然后使用上下文菜单选择 Find with...\Google 或我编程的任何其他站点.其中之一是我自己的文件,这会打开搜索框上的光标焦点,但不会出现任何文本.
I have a .htlm file on my hard drive is a list of my books and at the top there is a form and a script that allows me to search the content of the file. I like to access this file while I am browsing. I use Firefox with the extension "Advanced URL Builder" this extension allows me to highlight a few words and then using the context menu select Find with...\Google or any other site I have programmed in. One of these is my own file, this opens the cursor focus on the search box but no text will appear.
打开页面时的 URL 如下所示:
The URL when I open the page looks like this:
file:///F:/MyBooks.htm?search_txt=War and Peace
? 之后的 search_text是我在Advanced URL Builder"中编写的程序= 符号后面的部分是上一个站点或页面中突出显示的文本
the search_text after the ? is what I have programmed in "Advanced URL Builder" the portion after the = sign is the highlighted text from the previous site or page
我正在使用从网站上获取的这个表单和脚本:
I am using this form and script that I picked up from a website:
<form name="search" action="file:///F:/MyBooks.htm" method="post"
onSubmit="if(this.t1.value!=null && this.t1.value!='')
findString(this.t1.value);return false">
<input type="text" name="t1" id="search_txt" size=100 value="" />
<input type="submit" value="Find" name=b1>
</form>
<script language="JavaScript">
<!--
var TRange=null
function findString (str) {
if (parseInt(navigator.appVersion)<4) return;
var strFound;
if (window.find) {
// CODE FOR BROWSERS THAT SUPPORT window.find
strFound=self.find(str);
if (strFound && self.getSelection && !self.getSelection().anchorNode) {
strFound=self.find(str)
}
if (!strFound) {
strFound=self.find(str,0,1)
while (self.find(str,0,1)) continue
}
}
else if (navigator.appName.indexOf("Microsoft")!=-1) {
// EXPLORER-SPECIFIC CODE
if (TRange!=null) {
TRange.collapse(false)
strFound=TRange.findText(str)
if (strFound) TRange.select()
}
if (TRange==null || strFound==0) {
TRange=self.document.body.createTextRange()
strFound=TRange.findText(str)
if (strFound) TRange.select()
}
}
else if (navigator.appName=="Opera") {
alert ("Opera browsers not supported, sorry...")
return;
}
if (!strFound) alert ("String '"+str+"' not found!")
return;
}
//-->
</script>
我需要的是能够将 URL 的最后一部分作为变量传递给表单的第 4 行
What I need is to be able to pass the last portion of the URL to the 4th line of the form as a variable
<input type="text" name="t1" id="search_txt" size=100 value="War and Peace" />
你能帮忙吗?
谢谢.
推荐答案
我通过修改上面的脚本仅 1 行就解决了 %20 的问题 - 感谢 Kaleb 和我使用他们部分代码的所有其他人完成工作.
I solved the problem of the %20 by modifying the above script only 1 line - My thanks to Kaleb and all the others that I used portion of their codes to get the job done.
<script>
function getParameterValue(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( unescape(window.location.href) );
if( results == null )
return "";
else
return results[1];
}
function setSearchText() {
document.getElementById("search_text").value = getParameterValue("search_text");
}
var 结果 = regex.exec(unescape(window.location.href));通过将这一行更改为unescape",现在文本将进入搜索框而没有 %20.
var results = regex.exec( unescape(window.location.href) ); by changing this line with the word "unescape" now the text passes into the search box without the %20.
这篇关于如何将 URL 的结尾传递给 Value="";以一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!