javascriptjs区分大小写吗吗

JavaScript基础教程 列表
JavaScript 区分大小写区分大小写
JavaScript 语言是区分大小写的,不管是命名变量还是使用关键字的时候。
的例子,如果将 alert 命令改为 ALERT 或者 alerT 等:
&script type=&text/javascript&&
ALERT(&我是提示文字!&);
&div&图片及文字内容&/div&
使用 IE 浏览器运行该例子,会在下面的状态栏会有黄色的感叹号警告提示。双击该感叹号,可以看到完整的错误提示信息:
消息: 缺少对象
URI: file:///E:/web/html/alert.html
如果您使用别的浏览器,如 firefox 火狐浏览器,则可能需要通过第三方插件如 firebug 才能看到此错误提示信息。上面是一个使用 alert 命令关键字大写错误的例子,在 JavaScript 中,关键字都是小写的。对于变量名,函数名甚至函数参数等,都是需要区分大小写的。但和关键字不同, JavaScript 并没有要求它们一定需要小写,这些内容会在相关章节涉及到。
在编写 JavaScript 代码的过程中,常常需要调试编写过程中的错误,查看并定位代码中的错误,是非常必要的。
此外,浏览器提示的错误位置,也可能是由其他地方的逻辑导致的该处错误。因此,在排查错误时,经常需要结合上下代码逻辑一同检查。
本章节内容共分 6 部分:1.
JavaScript 区分大小写4.
<(我爱开发网) — 提供最好的 、、、 及JavaScript的indexOf忽略大小写
javascript中indexOf函数是严格区分大小写的,也就是当我们使用javascript的indexOf函数的时候,
是无法进行大小写同时进行的。为我们的一些字符串操作造成了困难。
下面像大家介绍如何让javascript中indexOf函数忽略大小写呢。
把他们全都换成大写或小写,再比较就可以了。
这是比较简单的一种做法!
indexOf对象内第一次出现子字符串的字符位置,
用toLowerCase或toUpperCase如下代码:
var testStr = 'ABCDEF';
var subStr = 'bcd';
alert(testStr.toLowerCase().indexOf(subStr.toLowerCase()));
testStr = 'AbCdEf';
alert(testStr.toLowerCase().indexOf(subStr.toLowerCase()));
或者看看下面这个是如何对indexof函数进行扩展的:
String.prototype.indexOf = function(f,m){
var mm = (m == false) ? "i":"";
var re = eval_r("/"+ f +"/"+mm);
var rt = this.match(re);
return (rt == null) ? -1:rt.
var test = "absnegKIugfkalg";
alert(test.indexOf("kiu",false));
下面这个兼容原来的
indexOf函数,可以加入直接拿来进行忽略大小写的javascript的indexOf函数操作了。
&script language="javascript"&
String.prototype._indexOf = String.prototype.indexOf;
String.prototype.indexOf = function()
if(typeof(arguments[arguments.length - 1]) != 'boolean')
&&&&&&&&&&&&&&&
return this._indexOf.apply(this,arguments);
&&&&&&&&&&&&&&&
var bi = arguments[arguments.length - 1];
&&&&&&&&&&&&&&&
var thisObj =
&&&&&&&&&&&&&&&
var idx = 0;
&&&&&&&&&&&&&&&
if(typeof(arguments[arguments.length - 2]) == 'number')
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&
idx = arguments[arguments.length - 2];
&&&&&&&&&&&&&&&&&&&&&&&
thisObj = this.substr(idx);
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
var re = new RegExp(arguments[0],bi?'i':'');
&&&&&&&&&&&&&&&
var r = thisObj.match(re);
&&&&&&&&&&&&&&&
return r==null?-1:r.index +
alert("bcssssasdfsdf".indexOf('A',3,true));
alert("bcssssasdfsdf".indexOf('a',3));
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。document.getElementById("xx").style.xxx中的所有属性是什么
盒子标签和属性对照
CSS语法(不区分大小写)
JavaScript语法(区分大小写)
border-bottom
borderBottom
border-bottom-color
borderBottomColor
border-bottom-style
borderBottomStyle
border-bottom-width
borderBottomWidth
border-color
borderColor
border-left
borderLeft
border-left-color
borderLeftColor
border-left-style
borderLeftStyle
border-left-width
borderLeftWidth
border-right
borderRight
border-right-color
borderRightColor
border-right-style
borderRightStyle
border-right-width
borderRightWidth
border-style
borderStyle
border-top
border-top-color
borderTopColor
border-top-style
borderTopStyle
border-top-width
borderTopWidth
border-width
borderWidth
floatStyle
margin-bottom
marginBottom
margin-left
marginLeft
margin-right
marginRight
margin-top
padding-bottom
paddingBottom
padding-left
paddingLeft
padding-right
paddingRight
padding-top
paddingTop
颜色和背景标签和属性对照
CSS 语法(不区分大小写)
JavaScript 语法(区分大小写)
background
background
background-attachment
backgroundAttachment
background-color
backgroundColor
background-image
backgroundImage
background-position
backgroundPosition
background-repeat
backgroundRepeat
样式标签和属性对照
CSS语法(不区分大小写)
JavaScript 语法(区分大小写)
list-style-type
listStyleType
list-style-image
listStyleImage
list-style-position
listStylePosition
list-style
white-space
whiteSpace
文字样式标签和属性对照
CSS 语法(不区分大小写)
JavaScript 语法(区分大小写)
font-family
fontFamily
font-style
font-variant
fontVariant
font-weight
fontWeight
文本标签和属性对照
CSS 语法(不区分大小写)
JavaScript 语法(区分大小写)
letter-spacing
letterSpacing
line-break
line-height
lineHeight
text-align
text-decoration
textDecoration
text-indent
textIndent
text-justify
textJustify
text-transform
textTransform
vertical-align
verticalAlign&
阅读(...) 评论()}

我要回帖

更多关于 javascript 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信