The data that’s being dynamically output on the page, this is the data that’s being fetched by ajax and I’m going to show it on the page
success:function(data){
var arr = data.split('_');
var numArr = arr[0].split(",");
var numStr = "";
if(numArr.length==undefined || numArr.length==0){
$("#phonenolist").html(' I'm sorry , The corresponding number was not found !');
}else{
for(var i=0;i<numArr.length;i++){
numStr += "<li><a id='n_"+i+"' href="javascript:choose_mobile("
+ numArr[i].toString()+",n_"+i+");" class='buy'>"
+ numArr[i].toString().substring(0, 3)
+ "<span class='org'> "
+ numArr[i].toString().substring(3, 7) + " "
+ numArr[i].toString().substring(7, 11)
+ "</span></a></li>";
}
$("#phonenolist").html(numStr);
}
index = arr[1];
total = arr[2];
$("#curr").html(' The first '+index+' page , A total of '+total+' page ');
}
function choose_mobile(num,id){
alert(num+" "+id);
$("#mobile").val(num);
$("#xhmobile").html("<h3><b>"+num+"</b></h3>");
$("#"+id).addClass("buy").siblings().removeClass("buy");
}
So my argument in js is going to be choose_mobile (number, object id), but when I execute js it just pops up the number, no id, so I was frustrated, and then I asked someone else, and in line 9, line 10, I put ’ ‘single quotes around the two arguments of the method,
numStr += "<li><a id='n_"+i+"' href="javascript:choose_mobile('"
+ numArr[i].toString()+"','n_"+i+"');" class='buy'>"
So it worked. I was so confused before that js parsing strings is not quite the same as parsing strings of Numbers