location.search

知识
张雷老师 2019-07-17 16:56:37

JS中location.search什么意思:
设置或获取 网页地址跟在问号后面的部分

当以get方式在url中传递了请求参数时,可以利用location的search属性提取参数的值

#location.search#

返回顶部

影响力:2203

js如何获取请求中的url以及参数

这个解答帮助过6953人

方法一、正则表达式
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
方法二、
<Script language="javascript">
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
</script>
方法三、
/**
* 获取指定的URL参数值
* URL:http://www.quwan.com/index?name=tyler
* 参数:paramName URL参数
* 调用方法:getParam("name")
* 返回值:tyler
*/
function getParam(paramName) {
paramValue = "", isFound = !1;
if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
}
return paramValue == "" && (paramValue = null), paramValue
}
其他参数获取介绍:
//设置或获取对象指定的文件名或路径。
alert(window.location.pathname);
//设置或获取整个 URL 为字符串。
alert(window.location.href);
//设置或获取与 URL 关联的端口号码。
alert(window.location.port);
//设置或获取 URL 的协议部分。
alert(window.location.protocol);
//设置或获取 href 属性中在井号“#”后面的分段。
alert(window.location.hash);
//设置或获取 location 或 URL 的 hostname 和 port 号码。
alert(window.location.host);
//设置或获取 href 属性中跟在问号后面的部分。
alert(window.location.search);

编辑时间 2019-01-13 12:15:13
影响力:6578

js如何准确获取当前页面url网址信息

这个解答帮助过673人

1、window.location.href(设置或获取整个 URL 为字符串)
var test = window.location.href;
alert(test);
返回:http://i.cnblogs.com/EditPosts.aspx?opt=1
2、window.location.protocol(设置或获取 URL 的协议部分)
var test = window.location.protocol;
alert(test);
返回:http:
3、window.location.host(设置或获取 URL 的主机部分)
var test = window.location.host;
alert(test);

4、window.location.port(设置或获取与 URL 关联的端口号码)
var test = window.location.port;
alert(test);
返回:空字符(如果采用默认的80端口(update:即使添加了:80),那么返回值并不是默认的80而是空字符)
5、window.location.pathname(设置或获取与 URL 的路径部分(就是文件地址))
var test = window.location.pathname;
alert(test);
返回:/EditPosts.aspx
6、window.location.search(设置或获取 href 属性中跟在问号后面的部分)
var test = window.location.search;
alert(test);
返回:?opt=1
PS:获得查询(参数)部分,除了给动态语言赋值以外,我们同样可以给静态页面,并使用javascript来获得相信应的参数值。
7、window.location.hash(设置或获取 href 属性中在井号“#”后面的分段)
var test = window.location.hash;
alert(test);
返回:空字符(因为url中没有)

编辑时间 2019-05-26
影响力:1351

这个c语言程序的binary search貌似只有一个错了,但是不知道怎么改,求大神帮忙

描述: /***helpers.c**HelperfunctionsforProblemSet3.*/#include<cs50.h>#include<stdio.h>#include"helpers.h"/***Returnstrueifvalueisinarrayofnvalues,elsefalse.*/boolsearch(intvalu... /**
* helpers.c
*
* Helper functions for Problem Set 3.
*/

#include <cs50.h>
#include <stdio.h>
#include "helpers.h"

/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value, int values[], int n)
{ int c, first, last, middle, search;

printf("Enter number of elements\n");
value = get_int();

printf("Enter %d integers\n", n);
values[];
for (c = 0; c < n; c++)

printf("Enter value to find\n");
search = get_int();

first = 0;
last = n - 1;
middle = (first+last)/2;

while (first <= last) {
if ( values[middle] < value)
first = middle + 1;
else if ( values[middle] == value) {
printf("%d found at location %d.\n", search, middle+1);
break;
}
else
last = middle - 1;

middle = (first + last)/2;
}
if (first > last)
printf("Not found! %d isn't present in the list.\n", value);

return 0;
}
/**
* helpers.c
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
#include <stdio.h>
#include "helpers.h"
/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value,int values[], int n)
{ int c, first, last, middle;
printf("Enter number of elements\n");
n = get_int();
printf("Enter %d integers\n", n);
values[] = get_int;
for (c = 0; c < n; c++)
printf("Enter value to find\n");
value = get_int();
first = 0;
last = n - 1;
middle = (first+last)/2;
while (first <= last) {
if ( values[middle] < value)
first = middle + 1;
else if ( values[middle] == value) {
printf("%d found at location %d.\n", value, middle+1);
break;
}
else
last = middle - 1;
middle = (first + last)/2;
}
if (first > last)
printf("Not found! %d isn't present in the list.\n", value);
return 0;
}
求改这个啊,原来那个不对
展开
这个解答帮助过6080人

虽然这个程序自定义了输入函数,但是二分查找的逻辑是没有错的,不知道你说的错误是什么。

编辑时间 2019-07-29
影响力:1268

用英语介绍一下google。

这个解答帮助过2084人

Introduction:Google is a Web search engine owned by Google, Inc, and is the most used search engine on the Web, related to its Internet search, e-mail, online mapping, office productivity, social networking, and video sharing services as well as selling advertising-free versions of the same technologies.Google receives several hundred million queries each day through its various services.

翻译:

简介:谷歌是谷歌公司拥有的网络搜索引擎,是互联网上使用最多的搜索引擎,与互联网搜索、电子邮件、在线地图、办公室生产力、社交网络、视频共享服务以及出售相同技术的广告免费版本有关。谷歌通过其各种服务每天接收数亿查询。

History of Google

Google began in January 1996, as a research project by Larry Page, who was soon joined by Sergey Brin, two Ph.D. students at Stanford University in California. They hypothesized that a search engine that analyzed the relationships between websites would produce better ranking of results than existing techniques, which ranked results according to the number of times the search term appeared on a page.Their search engine was originally nicknamed "BackRub" because the system checked backlinks to estimate the importance of a site. A small search engine called Rankdex was already exploring a similar strategy.

In March 1999, the company moved into offices in Palo Alto, home to several other noted Silicon Valley technology startups. After quickly outgrowing two other sites, the company leased a complex of buildings in Mountain View at 1600 Amphitheatre Parkway from Silicon Graphics (SGI) in 2003.The company has remained at this location ever since, and the complex has since come to be known as the Googleplex (a play on the word googolplex). In 2006, Google bought the property from SGI for US$319 million.

编辑时间 2019-04-25
影响力:8206

windows10系统下小娜搜索框变成白色如何处理

这个解答帮助过5727人

步骤如下:

1、新建记事本,将下面代码复制进去:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0]

"UILanguage"="zh-Hans-CN"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\CloudAgent_GlobalShell]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\CloudAgent_LaunchApplication]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\CloudAgent_Settings]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\CloudAgent_ShareFile]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\CloudMusic]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\DeviceManagementEnabled]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\ProactivePrefetchIntervalMinutes]

"Value"=dword:000002d0

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\PWILOActivityUploadEnabled]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxAutoSuggestedForegroundColor]

"Value"=dword:ff999999

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxBorderColor]

"Value"=dword:bbffffff

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxBorderColorInDarkMode]

"Value"=dword:bbffffff

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxBorderColorShouldMatchTaskbar]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxBorderColorShouldMatchTaskbarInDarkMode]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxBorderOnlyAtRest]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxBorderOnlyAtRestInDarkMode]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxBorderOnlyOnTop]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxBorderOnlyOnTopInDarkMode]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxBorderThickness]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxBorderThicknessInDarkMode]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxIbeamPointerOnHover]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxText]

"Value"="在这里输入你要搜索的内容"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyBackground]

"Value"=dword:00000014

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyBackgroundInDarkMode]

"Value"=dword:00000014

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyForeground]

"Value"=dword:0000003c

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyForegroundHighlight]

"Value"=dword:0000003c

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyForegroundHighlightInDarkMode]

"Value"=dword:0000003c

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyForegroundInDarkMode]

"Value"=dword:0000003c

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyHighlight]

"Value"=dword:0000001e

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyHighlightInDarkMode]

"Value"=dword:0000001e

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyTextLight]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyTextLightHighlight]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyTextLightHighlightInDarkMode]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxTransparencyTextLightInDarkMode]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchBoxUseSearchIconAtRest]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\SearchButtonUseSearchIcon]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\ShowSearchGlyphLeftOfSearchBox]

"Value"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\ShowSubmitButtonRightOfSearchBox]

"Value"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\WhiteSearchBox]

"Value"=dword:00000001

"Feature"="CAC01CT"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search\Flighting\0\WhiteSearchBoxInDarkMode]

"Value"=dword:00000001

2、在文本文章上点击【关闭】--【保存】;  

3、将新 建文本年文章.txt 修改为 新建文本文章.reg (若没有txt显示可参考“Win10怎么显示文件后缀名?”)   4、修改完成后双击运行修改好的 新建文本文章.reg 导入 即可 。

编辑时间 2019-06-28
影响力:3234

PHP查找mysql指定字段,并将同列另一字段赋值变量+1

描述: 比如我数据库表名:CS,有3个字段分别是id,nicheng,num,我想用表单搜索字段nicheng里某个记录值并显示出来,同时将同列字段num的变量记录+1,现在表单、数据库连接、搜索字段并显示... 比如我数据库表名:CS,有3个字段分别是id,nicheng,num,我想用表单搜索字段nicheng里某个记录值并显示出来,同时将同列字段num的变量记录+1,现在表单、数据库连接、搜索字段并显示结果的代码已经写好了,就是同列字段num添加变量记录+1还没弄出来。(其实大概含义就是搜索某人名字显示搜索结果并显示搜索访问量)下面是代码,望大神指教!!(字段除了id,其他类型都是varchar)index.html:<form method="post" action="num.php" name="search" /><input name="search" type="text" value="" size="20" /> <input type="submit" value="按昵称搜索" /></form>-------------num.php:<?phprequire_once 'config.php'; $searchs = $_POST['search']; //传递search框过来的值 $searchs= trim($searchs);$result = mysql_query("SELECT * FROM CS where nicheng like '%$searchs%'");if (mysql_num_rows($result) < 1) echo '<script language="JavaScript">;alert("没有搜索的昵称!");location.href="index.php";</script>;';?>



展开

这个解答帮助过8327人

num.php:
<?phprequire_once 'config.php';
$searchs = $_POST['search']; //传递search框过来的值
$searchs= trim($searchs);
$result = mysql_query("SELECT * FROM dunling_chat where nicheng like '%$searchs%' and num = num +1");
if (mysql_num_rows($result) < 1) echo '<script language="JavaScript">;alert("没有搜索的昵称!");location.href="index.php";</script>;';?>

编辑时间 2019-03-13
影响力:8866

JS地址栏中字符串转对象,怎么转?

描述: 图一是我对象转字符串得代码,图二是字符串转对象得代码,求大神教下怎么字符串转对象... 图一是我对象转字符串得代码,图二是字符串转对象得代码,求大神教下怎么字符串转对象

这个解答帮助过1778人

咋又是你,你不是已经把转换的逻辑写出来了吗

var search = window.location.search;
     var obj = {};
     var keyValues = search.slice(1).split("&");
     keyValues.forEach(function(keyValue){
     var tempArr = keyValue.split("=");
     var key = tempArr[0];
     var value = tempArr[1].indexOf("|") > 0 ? tempArr[1].split("|") : tempArr[1];
     obj[key] = value;
     });

编辑时间 2019-12-02
影响力:3444

如何在这个页面加载另一个页面而且用js能回去加载页面的值

这个解答帮助过7946人

window.location.href = "url?key1=value1&key2=value2&....";
如demo.html?uersid=123&password=123456这样。
取值只需要在DEMO页面用JS,
function getRequest() {
var url = decodeURI(location.search); //获取url中?后的字符串 decondeURI解码url
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
var strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
使用:
var request = getRequest();
var userid = request["userid"] == null ? "" : request["userid"];
var password = request["password"] == null ? "" : request["password"];
注意因为编码问题url传中文参数会乱码,所以整个href里面的类容需(url+参数)要先用
encodeURI(url+参数)这个原生方法编码一下,在通过上面function中的decodeURI(location.search);解码就可以取到正常的中文字符了。

编辑时间 2019-01-18
影响力:5696

js 代码问题

描述: i(1),i(2),i(3),i(4),i(5),i(6);vars=i(7),a=i(175);window.developmentMode=!1,window.buildVersion="1.30.9",window.location.search.slice(1).split(";").map(function(e){vart=e.... i(1), i(2), i(3), i(4), i(5), i(6);
var s = i(7),
a = i(175);
window.developmentMode = !1, window.buildVersion = "1.30.9", window.location.search.slice(1).split(";").map(function(e) {
var t = e.split("=");
switch (t[0]) {
case "appVersion":
window.appInfo = window.appInfo || {}, window.appInfo.version = t[1]
}
}), a.isAndroid && window.MobileAccessibility && window.MobileAccessibility.usePreferredTextZoom(!1), window.assetPreloader = i(189), window.dofus = i(193);
var r = document.createElement("div");
r.id = "dofusBody", document.body.appendChild(r);
var l = i(320),
c = i(436);
window.gui = new c, window.foreground = new l;
var d = i(405),

i()小括号里面的数字是什么意思?i在代码里看上去不是一个function
展开
这个解答帮助过3168人

代码不全, 看不出来具体. 猜测是一个 js 打包工具(webpack等)打包出来的代码, 然后被压缩了. i 在这里应该是 commonjs 规范中的 require 函数. 数字是 commonjs 模块的索引值

编辑时间 2019-05-12