【问题标题】:Conflict between $(document).ready and prototype.js$(document).ready 和prototype.js 之间的冲突
【发布时间】:2014-05-13 16:58:14
【问题描述】:

当我包含$(document).ready 时,prototype.js 有这个问题 在我的网页中它不起作用。

这是我的代码的一部分:

<script type="text/javascript" src="<?php echo base_url();?>asset/scripts/prototype.js"></script>
<script type="text/javascript">    
  function nl2br (str, is_xhtml) {   
    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';    
    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
  }

  $(document).ready(function(){
    $('#sendmail2').on('submit', function(){
      alert('Ok');
    });
  });           
</script>

但是当我删除原型时,脚本可以正常工作。

【问题讨论】:

    标签: jquery html prototypejs document-ready


    【解决方案1】:

    用扩展名“jQuery”更改所有“$”

    jQuery(document).ready(function(){
    

    【讨论】:

    • 你在原型之前包含 jQuery 吗?这除了使用“jQuery”代替“$”
    【解决方案2】:
    【解决方案3】:

    尝试使用

    jQuery(document).ready
    

    而不是

    $(document).ready
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-07
      • 2019-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 2012-05-15
      相关资源
      最近更新 更多