JS gets the solution of the object null _javascript tips

Source: Internet
Author: User
The data that is dynamically output on the page, this is the data that Ajax obtains I want to show on the page
Copy Code code as follows:

Success:function (data) {
var arr = Data.split ('_');
var Numarr = Arr[0].split (",");
var numstr = "";
if (numarr.length==undefined | | numarr.length==0) {
$ ("#phonenolist"). HTML (' Sorry, no query to the corresponding number! ');
}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 (' +index+ ' page, total ' +total+ ' page ');
}
function Choose_mobile (num,id) {
Alert (num+ "" +id);
$ ("#mobile"). Val (num);
$ ("#xhmobile"). HTML ("$ ("#" +id). addclass ("buy")-siblings (). Removeclass ("buy");
}

In JS, my parameters are probably like this, Choose_mobile (number, object ID), but in the execution of JS only pop up the number, no ID, so I am very depressed, and then ask someone else, in the code 9th, 10 lines, to the method of two parameters with ' single quotes,
Copy Code code as follows:

Numstr + = "<li><a id= ' N_" +i+ "href=\" Javascript:choose_mobile (' "
+ numarr[i].tostring () + "', ' N_" +i+ "); \" class= ' Buy ' > "

So successful, before let me good entanglements, JS to string parsing with the number string parsing is still not the same ah, divided so clear

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.