假設有個方法/* index為數字或字符串數字 */
function test(index) { // index驗證預處理 return $('input').eq(index).val();
}如何確保eq正確執行?我根據大家的答案寫了個結果,應該長這樣:function test(index) { /^[+-]?\d+$/.test(index) ? index = parseInt(index) : index = 0; return $('input').eq(index).val();
}大家看看如何?另外大家回答都差不多,所以采納第一個回答的人了,3q!
js如何判斷一個方法的參數為數字確保方法體里的eq正確執行
慕姐4208626
2018-08-13 10:09:06