Я нахожусь в процессе создания моего первого плагина jQuery, который будет автоматически форматировать числа в различные международные форматы. В плагине есть пара функций, которые очищают строки и переформатируют строку, которую нужно вызвать из другого скрипта jQuery.
На основании приведенной ниже структуры подключаемого модуля (дайте мне знать, если вам нужен весь код), могу ли я позвонить и отправить параметры в функции stripFormat(ii)
и targetFormat(ii, iv)
?
Или мне нужно изменить структуру моего плагина, и если да, то как?
(function($){
var p = $.extend({
aNum: '0123456789',
aNeg: '-',
aSep: ',',
aDec: '.',
aInput: '',
cPos: 0
});
$.fn.extend({
AutoFormat: function() {
return this.each(function() {
$(this).keypress(function (e){
code here;
});
$(this).keyup(function (e){
code here;
});
// Would like to call this function from another jQuery script - see below.
function stripFormat(ii){
code here;
}
// Would like to call this function from another jQuery script - see below.
function targetFormat(ii, iv){
code here;
}
});
}
});
})(jQuery);
Методы, пытающиеся вызвать функции плагина:
jQuery(function(){
$("input").change(function (){ //temp function to demonstrate the stripFormat() function.
document.getElementById(targetElementid).value = targetFormat(targetElementid, targetValue);
});
});
Я пытался использовать эти варианты без успеха:
document.getElementById(targetElementid).value = $.targetFormat(targetElementid, targetValue);
document.getElementById(targetElementid).value = $.autoFormat().targetFormat(targetElementid, targetValue);