社区
JavaScript
帖子详情
indexOf()使用出错
chocolateboy
2005-01-16 11:03:31
页面路径:http://gxy/xby/test.htm
var thisUrl = "";
thisUrl = window.location; //如果这一行我写成 thisUrl = "http://gxy/xby/test.htm" 则没问题
if(thisUrl.indexOf("/cn/")!=-1){ //这一行出错,提示对象不支持此属性或方法
...
}
...全文
392
11
打赏
收藏
indexOf()使用出错
页面路径:http://gxy/xby/test.htm var thisUrl = ""; thisUrl = window.location; //如果这一行我写成 thisUrl = "http://gxy/xby/test.htm" 则没问题 if(thisUrl.indexOf("/cn/")!=-1){ //这一行出错,提示对象不支持此属性或方法 ... }
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
boneeater
2005-01-17
打赏
举报
回复
thisUrl = window.location; 改成thisUrl = window.location.url;就OK啦^_^
cxz7531
2005-01-17
打赏
举报
回复
thisUrl = window.location.toString()
或者
thisUrl = ""+window.location;
梅雪香
2005-01-16
打赏
举报
回复
thisUrl = window.location.href;
seeu1688
2005-01-16
打赏
举报
回复
不,window.location确实是对象,只是他的toString()方法会呈现出window.location.href值
alert时对象会默认调用该对象的toString()方法,所以程序字符串
而赋值时也会调用toString()方法的,即对其href属性赋值。
确实不严谨,但dom约定俗成的东西简化倒也并非大问题,只要明白概念
ice_berg16
2005-01-16
打赏
举报
回复
手册上说:
location.href是location的默认属性
设置location='http://microsoft.com' 和设置
location.href='http://microsoft.com'.
是相同的
deerchao
2005-01-16
打赏
举报
回复
thisUrl = window.location.href;
chocolateboy
2005-01-16
打赏
举报
回复
?是对象?为什么alert(window.location);不显示 [object] 而显示路径信息?
或者说我们经常window.location='http://url';。这样写是不严谨的做法?
zhangfire
2005-01-16
打赏
举报
回复
thisUrl = window.location.href;
leojay1
2005-01-16
打赏
举报
回复
enen
seeu1688
2005-01-16
打赏
举报
回复
将location对象转化为它的字符串形式
thisUrl = window.location; => thisUrl = window.location.toString();
meizz
2005-01-16
打赏
举报
回复
window.location 是一个对象
window.location.href 返回的才是当前网页的链接字符串
js:数组中的
Indexof
()方法和字符串中的
Indexof
()
数组中的
Indexof
():返回数组中元素第一次出现的索引值。 如果检索到元素,则返回元素在数组中首次出现的索引位置;否则返回-1. var arr2=[1,2,3,1,4,2,5]; document.write(arr2.
indexOf
(1,2)+'<br />'); // ...
vue.js中报错: TypeError: Cannot read property '
indexOf
' of undefined
[Vue warn]: Error when evaluating expression "name.
indexOf
('jack') >= 0": TypeError: Cannot read property '
indexOf
' of undefined ypeError: Cannot read property '
indexOf
' of undefined,从这句话中...
indexOf
()查找错误;
在项目开发过程中,有时候需要用
indexOf
() 进行匹配,但是通过
indexOf
() 判断的字符在判断内容前段部分同而后端部分不相同的情况下,会出现查找错误的情况; 列: limit.
indexOf
( 'Function_Session_Agenda_...
报错:directory index of “xxx“ is forbidden
directory index of "xxx" is forbidden 其中,xxx是在/etc/nginx/nginx.conf中指定的root目录。 报错根因:直接
使用
IP地址和端口号访问时,需要指定index,如果未指定,出现该报错。 这时候,可以在/etc/ng
js关于
indexOf
的
使用
要注意的问题
indexOf
()
使用
的是严格的 === 比较,即值和数据类型必须都相等。 js的数据类型基本分为六种:number、string、boolean、null、undefined、object(但object又可细分为Funtion、Array、Date、···) 所以在判断的...
JavaScript
87,992
社区成员
224,688
社区内容
发帖
与我相关
我的任务
JavaScript
Web 开发 JavaScript
复制链接
扫一扫
分享
社区描述
Web 开发 JavaScript
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章