var QuestionID = []; var answeridvalue = [];
////javascript Array Extended indexOf () method
Array.prototype.indexOf = function (e) {
for (var i = 0, j; j = This[i]; i++) {
if (J.indexof (e)! =-1) {
return i;
}
}
return-1;
}
if (Answeridvalue.length < 14) {
Alert ("Please answer 13 questions");
return false;
} else if (questionid.length = = && Answeridvalue.indexof (questionid[12] + ' | ')! =-1) {
$ ("#pagingForm"). attr ("Action", "@Url. Action (" Questionation "," Questionsubmit ")");
Form.submit ();
document.getElementById ("Pagingform"). Submit ();
} else {
Alert ("Please answer 13 questions");
return false;
}
QuestionID:
-------------------------------------
$ ("Input[name=questionid]"). each (function () {
Questionid.push ($ (this). Val ());
});
Answeridvalue:
---------------------------------------------------
$ ("input[name=answeridvalue]:checked"). each (function () {
var QuestionID = $ (this). attr ("Data-questionid");
var Qtype = $ (this). attr ("Data-type");
if (Qtype = = 2) {
Answeridvalue.push (QuestionID + "|" + $ (This). Val ());
$ (this). Val (QuestionID + "|" + $ (This). Val ());
var answeritemid = [];
Answeritemid.push (QuestionID + "|" + $ (This). Val ());
$ ("#answerItemId" + QuestionID). Val (Answeritemid);
} else {
Answeridvalue.push ($ (this). Val ());
}
});
----------------------------------------------------------------
1.ANSWERIDVALUE:ARRAY[18]
0: "14|11"
1: "14|13"
2: "14|14"
3: "14|19"
4: "14|20"
5: "14|23"
6: "15|25"
7: "16|28"
8: "17|34"
9: "17|35"
10: "17|36"
11: "18|62"
12: "18|63"
13: "19|58"
14: "19|59"
15: "20|54"
16: "20|55"
17: "21|51"
----------------------------------------------------------------
- QuestionID: array[13]
- 0: "+"
- 1: "the "
- 2: "+"
- 3: "+"
- 4: "All"
- 5: "+"
- 6: " the"
- 7: "+"
- 8: "a"
- 9: "All"
- Ten: "
- One: " "
- : "+"
- Length:
---------------------------------------------------------
JS to determine how an array contains a value
To determine if the array contains element elements
Example 1:
Array.prototype.contains = function (Element) {
for (var i = 0; i < this.length; i++) {
if (this[i] = = Element) {
return true;
}
}
return false;
}
This allows you to call this method directly to judge.
var arr = new Array ();
if (Arr.constains ("ddd")) {
Arr[i] = "DFSDFSD";
}
http://bbs.csdn.net/topics/360007998
---------------------------------------
Instance 2:javascript version Array.prototype.indexOf and Array.prototype.lastIndexOf method extension
Http://bbs.blueidea.com/thread-2853519-1-1.html
Array.prototype.indexOf = function (e) {
for (var i=0,j; j=this[i]; i++) {
if (j==e) {return i;}
}
return-1;
}
Array.prototype.lastIndexOf = function (e) {
for (var i=this.length-1,j; j=this[i]; i--) {
if (j==e) {return i;}
}
return-1;
}
Then the LZ can do this:
var a =[' red ', ' blue ', ' green ', ' blue ';
Alert (A.indexof ("Blue"));
Alert (A.lastindexof ("Blue"));
JS judgment array contains a value of the method and JavaScript array extension indexof () method