以下函数旨在实现indexOfIE中的属性.如果你曾经不得不这样做,我相信你以前见过它.
if (!Array.prototype.indexOf){
Array.prototype.indexOf = function(elt, from){
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;
for (; from < len; from++){
if (from in this &&
this[from] === elt)
return from;
}
return -1;
};
}
Run Code Online (Sandbox Code Playgroud)
我想知道作者在初始长度检查中使用三个大于标志是否常见?
var len = this.length >>> 0
在控制台中执行此操作只会返回我传递给它的对象的长度,而不是true或false,这让我想到了语法的目的.这是一些我不了解的高级JavaScript忍者技术吗?如果是的话,请赐教!
JavaScript >>>运算符有什么作用?
例如,alert(1 >>> 2).
我们如何使用它?
我有一个要求,我根据JSON响应动态创建单选按钮.到目前为止,我所做的Chrome和Firefox的作品,但给Object doesn't support this property or method上if(subItem[1].indexOf(",") >= 0)线
我的代码
$("#sList").live("change", function(){
var currentService=this.value;
var c1Svc=[];
var c2Svc=[];
if(absP.length==2)
{
$.each(compareServiceData,function(i,item){
if(currentService==item[0])
{
var configCount=0;
$.each(item[1],function(j,subItem){
var temp=subItem[1];
/*The JSON response contains List of Lists, so here if it contains a list it will be separated by "," so split it and store in a array, else directly store in a array*/
if(subItem[1].indexOf(",") >= 0)
{
var tList=temp.split(",");
$.each(tList,function(k,val){
if(configCount==0)
{
c1Svc.push(val);
}
else
{
c2Svc.push(val); …Run Code Online (Sandbox Code Playgroud) html javascript jquery internet-explorer internet-explorer-8