シンプルな jquery プラグインを作成しようとしています。ここに私がこれまでに得たもののリンクがあります
(function ($) {
$.bsDatepicker= function(element) {
var $element=$(element);
$element.attr("readonly","readonly");
$element.on("mousedown",function(){
renderCalendar();
});
renderCalendar = function(){
alert($element.attr("name"));
}
}
$.fn.bsDatepicker = function(options) {
return this.each(function() {
$abc=$(this);
// if element has a date picker already attached
if (undefined != $(this).data('bsDatepicker')) {
// get reference to the previously attached date picker
var plugin = $(this).data('bsDatepicker');
// remove the attached icon (if it exists)...
}
// create a new instance of the plugin
var plugin = new $.bsDatepicker(this, options);
// save a reference to the newly created object
$(this).data('bsDatepicker', plugin);
});
}
})(jQuery)
$(document).ready(function(){
$("#cal").bsDatepicker();
$("#cal2").bsDatepicker();
});
私が直面している問題は、このプラグインを異なる名前と ID を持つ 2 つのテキスト ボックスに実装することです。mousedown イベントでコンソールに要素名を出力しました。ここでの問題は、常に 2 番目のテキスト ボックス名を出力することです。クリックされている要素の名前を出力する必要があります。ここで何が間違っていますか?どんな助けでも大歓迎です。
ありがとう