対話している要素のクラスに応じて、他の関数を呼び出す関数を作成しようとしています。
if ステートメントを使用する代わりに、要素のクラスを使用して関数を呼び出せるようにしたいと考えています。以下の例:
function validate(thisInput){
var thisClass = thisInput.attr("class").split(' ')[0];
validate + class(thisInput);
/*This is what I would like to happen:
the class is grabbed from above, then that class name (whatever it is)
calls it's own function. I will be creating a function for each class.
*/
}
function validateClassname(thisInput) {
//do something
}
ご覧のとおり、クラス名を見つけて、それを独自の関数にして (if ステートメントを使用せずに)、その関数に必要なことを実行させようとしています。
私はこれを間違って見ていますか?私はそれについて別の方法で行くべきですか?ありがとうございました