我寫了1-2 jQuery插件,但他們都失敗了,當我嘗試使用多個實例....我沒有找到任何解決方案。請看下面的代碼,如果你在這個插件上創建2個實例,它不工作....這個代碼有什麼問題。什麼使得插件能夠運行多個實例?jquery插件多個實例不工作
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
</head>
<script src="jquery.js"></script>
<script>
(function($){
$.fn.truncate = function(options) {
return this.each(function() {
obj = $(this);
var body = obj.html();
$(obj).focus(function(){
alert($(obj).attr("id"));
});
});
};
})(jQuery);
</script>
<SCRIPT LANGUAGE="JavaScript">
<!--
$().ready(function(){
$('#t1').truncate();
$('#t2').truncate();
});
//-->
</SCRIPT>
<body>
<input type="text" id="t1">
<input type="text" id="t2">
</body>
</html>
Ahhhaaaa現在已經很清楚了......我甚至嘗試過添加選項......它的工作......感謝朋友.....我不會再繼續在我的插件中實現它,現在它只支持單個實例。 – 2011-12-18 10:39:30