不知道我在做什麼不正確。我在我的自定義jQuery插件中有一個函數,我的瀏覽器告訴我它是未定義的。jQuery自定義插件undefined js函數
任何人都可以看到我做了什麼錯內部:
(function($){
$.fn.myCustomPlugin = function() {
return this.each(function() {
var theValue = $(this).text().trim().replace(/ /g,'');
// STOP if theValue return nothing
if (theValue === null || theValue === undefined || theValue == ""){
$(this).html("nothing inside the span");
return true;
}
function clickActions()
{
alert("This alert shows when clicking on the element");
return false;
}
$(this).html('<a href="javascript:void(0);" onClick="clickActions()">'+theValue+'</a>');
}); // eof .each
};
})(jQuery);
的HTML是簡單的電話號碼裏面涵蓋:
<span class="formatme">123-8749674</span><br />
<span class="formatme">123-8749674</span><br />
<span class="formatme">123-8749674</span><br />
<span class="formatme">123-8749674</span><br />
<span class="formatme">123-8749674</span><br />
<script type="text/javascript">
$(document).ready(function() {
$('.formatme').myCustomPlugin();
});
</script>
功能clickActions()在錯誤的地方可能是簡單地,但是我已經將它移到了插件代碼中,結果相同。
究竟是什麼錯誤? – Madbreaks
檢查我的答案。 –