【问题标题】:the first jquery code is not working.....is it because of jQuery conflict第一个 jquery 代码不起作用.....是因为 jQuery 冲突吗
【发布时间】:2015-03-16 13:16:23
【问题描述】:

在这两个 jQuery 之间,我编写的第二个不起作用。

我猜是jQuery冲突的情况。

请帮忙....

<script>
 //this is the first jQuery code

  jQuery( document ).ready(function( $ ) {
  $(function() {

  $(document).ready(function(){
   $('.rm option').each(function(){
      if($(this).text()==$('div#disp').text())
          $(this).attr('selected','selected');
                });
            });

//this is the second jQuery code
$(function() {
$( "#dialog" ).dialog({
  autoOpen: false,
  show: {
    effect: "blind",
    duration: 800
  },
  hide: {
    effect: "blind",
    duration: 500
  }
    });

    $( "#opener" ).click(function() {
      $( "#dialog" ).dialog( "open" );
    });
  });    $(function () { $('#dialog').dialog({       keyboard: true    })});
  </script>

【问题讨论】:

  • 你为什么要编写一个就绪事件处理程序,它设置一个就绪事件处理程序,它设置一个就绪事件处理程序?
  • jQuery( document ).ready(function(){ === $(function() {
  • 省略第一行......仍然无法正常工作......我添加了该行,因为有人告诉我它可以解决问题。
  • jQuery( document ).ready 等于 $(document).ready, cos '$' 等于 'jQuery' .
  • 除了您有多个准备好的处理程序之外,您是否还有任何 javascript 错误?仅仅看它,看起来你已经打开了许多尚未关闭的括号,尽管由于格式的性质我可能是错误的

标签: javascript jquery


【解决方案1】:

试试这个:

 <script type='text/javascript'>

  $(document).ready(function(){

      $.each($('.rm option'), function( index, value ) {
        if( $(this).text() == $('div#disp').text() ){
          $(this).attr('selected','selected');
        }
      });

    $( "#dialog" ).dialog({
      autoOpen: false,
      show: {
        effect: "blind",
        duration: 800
      },
      hide: {
        effect: "blind",
        duration: 500
      },
    keyboard: true    
    });

    $( "#opener" ).click(function() {
      $( "#dialog" ).dialog( "open" );
    });


  });
</script>

我修复了无用的 '}' 并删除了无用的 .ready 和函数,并将 .each 更改为 $.each

ps。已编辑,抱歉,立即尝试。

【讨论】:

    猜你喜欢
    • 2016-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    相关资源
    最近更新 更多