我正在尝试学习构建自己的 jquery 插件。用一个简单的例子,但我在执行它时遇到错误。计划构建插件
贷款计算器
可以帮助我解决错误“
预期对象
我在 index.html 中的 javascript 是这样的......
$(function(){
$('#btn').click(function() {
var roi=getie(); // ROI - rate of interest - value of i receved from function getie()
$("#i").val(roi); // input type 'text ' to display Interest (i) value
});
});
和用于自定义功能的插件 codgin
盖蒂()
像这样分开
计算.js 文件
代码 :
(function($){
//Attach this new method to jQuery
$.fn.extend({
//This is where you write your plugin's name
getie: function() {
//Iterate over the current set of matched elements
return this.each(function() {
var i=20;
return i;
});
}
});
})(jQuery);
我正在使用 jquery-1.7.2.min.js 和 query-ui-1.8.20.custom.min.js 作为其他 js 文件。