Home  >  Article  >  Web Front-end  >  js获取对象为null的解决方法_javascript技巧

js获取对象为null的解决方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:13:181306browse

页面上动态输出的数据,这是ajax获取的数据我要在页面上展示

复制代码 代码如下:

    success:function(data){ 
        var arr = data.split('_'); 
        var numArr = arr[0].split(","); 
        var numStr = ""; 
        if(numArr.length==undefined || numArr.length==0){ 
            $("#phonenolist").html('对不起,没有查询到相应的号码!'); 
        }else{ 
            for(var i=0;i                numStr += "
  •                     + numArr[i].toString()+",n_"+i+");\" class='buy'>" 
                        + numArr[i].toString().substring(0, 3) 
                        + "
                        + numArr[i].toString().substring(3, 7) + " " 
                        + numArr[i].toString().substring(7, 11) 
                        + "
  • "; 
                    } 
                    $("#phonenolist").html(numStr); 
                } 
                index = arr[1]; 
                total = arr[2]; 
                 $("#curr").html('  第'+index+'页,共'+total+'页 '); 
            } 
         function choose_mobile(num,id){ 
            alert(num+" "+id); 
            $("#mobile").val(num); 
            $("#xhmobile").html("

    "+num+"

    "); 
            $("#"+id).addClass("buy").siblings().removeClass("buy"); 
        } 

    在js里面我的参数大概是这样子,choose_mobile(号码,对象id),但是在执行js的时候只弹出了号码,没有id,这样我很郁闷,后来又请教别人,在代码第9,10行,给方法的两个参数加上了‘'单引号,
    复制代码 代码如下:

    就这样成功了,之前让我好纠结,js对字符串的解析跟对数字串的解析还是不太一样啊,分的这么清
    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn