好吧,所以我創建了一個各種分級。你加在你的第一個和最後一個名稱,等級,並把它添加到表(它的工作原理,當我在Chrome上運行,而不是在的jsfiddle出於某種原因,這是不是問題)訂購數組問題
https://jsfiddle.net/bhLhayar/
我遇到的問題是分揀。我的單選按鈕說「未定義」,但我認爲我已經在我的JS中定義了它們。請諮詢? XD
function sortby(what){
if(what == 'firstN'){studentdata.sortbyfirstSet();}
if(what == 'lastN'){studentdata.sortbylastSet();}
if(what == 'gradeUp'){studentdata.sortbygradeSetUp();}
if(what == 'gradeDown'){studentdata.sortbygradeSetDown();}
updatetable()
}
這裏是我認爲我出錯的代碼?與此有關:
sortbyFirstSet(){
this.data.sort(function (one, two){
if(one.firstName > two.firstName){return 1}
if(one.firstName < two.firstName){return -1}
if(one.firstName == two.firstName){return 0}
});
}
sortbylastSet(){
this.data.sort(function (one, two){
if(one.lastName > two.lastName){return 1}
if(one.lastName < two.lastName){return -1}
if(one.lastName == two.lastName){return 0}
});
}
sortbygradeSetUp(){
this.data.sort(function (one, two){
if(one.finalGrade > two.finalGrade){return 1}
if(one.finalGrade < two.finalGrade){return -1}
if(one.finalGrade == two.finalGrade){return 0}
});
}
sortbygradeSetDown(){
this.data.sort(function (one, two){
if(one.finalGrade < two.finalGrade){return 1}
if(one.finalGrade > two.finalGrade){return -1}
if(one.finalGrade == two.finalGrade){return 0}
});
}
你說什麼單選按鈕?我沒有看到任何HTML代碼。 –
我放了一個jsfiddle.net的鏈接 – JHillman
至少在jsFiddle中,看起來沒有一個'onclick =「」'屬性可以正常工作。使用'.addEventListener'至少適用於'Info Submit'按鈕。 –