jQuery美元.Fn不工作,没有错误

jQuery $.fn not working with no errors

本文关键字:有错误 工作 美元 Fn jQuery      更新时间:2023-09-26

我以前见过这个问题,我在谷歌上搜索过,但是没有用。我试图学习如何在jQuery中创建自己的函数,但它不做我所要求的,我没有收到任何错误。我做错什么了吗?

脚本

<script type='text/javscript'> 
    (function($){ 
        $.fn.selectMe = function(options){ 
            return this.each(function(){ 
               $(this).find('li').append("<input type='checkbox'>"); 
            }); 
        } 
    }(jQuery)); 
    $(document).ready(function(){ 
        $('.Select').selectMe(); 
    }); 
</script>

为了更好地衡量,这里是HTML

<div class='Select'>
    <p>Cuisine Types (3/10)</p>
    <ul>
        <li>American</li>
        <li>Italian</li>
        <li>Chinese</li>
    </ul>
</div>

谢谢!

不确定这个问题。但我注意到:

  • <script type = 'text/javscript'>应该是<script type='text/javascript'>
  • (function ($) { }(jQuery));应为:(function($){ })(jQuery);

这个效果很好。试试这个:

(function($){
	$.fn.selectMe = function (options) {
		return this.each(function () {
			$(this).find('li').append("<input type = 'checkbox'>");
		});
	}
})(jQuery);
$(document).ready(function () {
	$('.Select').selectMe();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class = 'Select'>
    <p>Cuisine Types (3/10)</p>
    <ul>
        <li>American</li>
        <li>Italian</li>
        <li>Chinese</li>
    </ul>
</div>

Ok!Facepalm指!我真不敢相信我浪费了两个小时在这上面,浪费了大家的时间。我把javascript拼错了,它抛出了所有的代码,但没有错误。我很抱歉,但感谢你所有的反馈!