this.form.elements
が返すのと同じ型の配列を配列キーとして取得する必要があります。jQuery - 入力名をキーとして配列を取得する
私はthis.toArray()
を試しましたが、同じように見えますが、名前キーがありません(キーは数字です)。シリアル化が可能な選択肢であることを利用して
(function($) {
$.fn.blah = function(){
var that = this;
return this.each(function(){
$(this).bind('change', function(){
var matches1 = that.toArray(); // this doesn't work
var matches2 = this.form.elements; // this works.
console.log(matches1); // but both arrays look the same. wtf?
console.log(matches2);
return true;
}).change();
});
};
})(jQuery);
$("input").blah();
これは 'this 'の値が何であるかによって異なります。 – Anurag
それはセレクタのセットです、 '$(" input ")から来ますsomefunction()....' – Alex