I have this problem with prototype.js when I include $(document).ready in my webpage it doesn't work.

Here is part of my code:

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

But when I remove prototype the script works fine.

有帮助吗?

解决方案

change all "$" with extended name "jQuery"

jQuery(document).ready(function(){

其他提示

Try using

jQuery(document).ready

instead of

$(document).ready
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top