简体   繁体   English

jQuery $ .fn不能正常运行

[英]jQuery $.fn not working with no errors

I've seen this question asked before and googled but to no avail. 我之前曾问过这个问题,并且用谷歌搜索,但无济于事。 I'm trying to learn how to create my own function in jQuery but it doesn't do what I'm asking and I'm not receiving any errors. 我正在尝试学习如何在jQuery中创建我自己的函数,但是它不能满足我的要求,并且没有收到任何错误。 Have I done something wrong here? 我在这里做错了吗?

Here's the script 这是剧本

<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>

For good measure, here's the HTML 很好,这是HTML

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

Thanks! 谢谢!

Not sure with the problem though. 虽然不确定该问题。 but I observed: 但我观察到:

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

This works great. 这很好。 Try this: 尝试这个:

 (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! Facepalm! I can't believe I wasted 2 hours on this and everyones time. 我不敢相信我在这个和每个人的时间上浪费了2个小时。 I spelled javascript wrong and it threw off all the code but no errors. 我将javascript拼写错误,并删除了所有代码,但没有错误。 I'm sorry all but thank you for all the feedback! 抱歉,谢谢您的反馈!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM