jquery对话框丢失:属性id错误后

时间:2013-05-13 09:54:01

标签: javascript json

我正在尝试弹出jquery对话框。 当我对话  有以下代码..

var opt = {
        autoOpen: false,
        modal: true,
        width: 550,
        height:650,
        title: 'Details'
};

工作正常。我得到了弹出窗口。但添加其他信息让我犯了这个错误。

更新帖子

 <script>
$(document).ready(function(){

 $(".editbt").click(function(event) {
    event.preventDefault();

     $.ajax({
        type: "GET",
        url: this.href,
        cache:false,
        success: function(response){
        var opt = {
         box :$( "#box" ),
      itemname:$( "#itemname" ),
      size:$( "#size" ),
      potency:$( "#potency" ),
      quantity:$( "#quantity" ),

      allFields:$( [] ).add( box ).add(itemname).add(size).add(potency).add(quantity),
      tips :$( ".validateTips" );

    function updateTips( t ) {
      tips
        .text( t )
        .addClass( "ui-state-highlight" );
      setTimeout(function() {
        tips.removeClass( "ui-state-highlight", 1500 );
      }, 500 );
    }


  function checkLength( o, n, min, max ) {
      if ( o.val().length > max || o.val().length < min ) {
        o.addClass( "ui-state-error" );
        updateTips( "Please enter the field " );
        return false;
      } else {
        return true;
      }
    }
    function checkRegexp( o, regexp, n ) {
      if ( !( regexp.test( o.val() ) ) ) {
        o.addClass( "ui-state-error" );
        updateTips( n );
        return false;
      } else {
        return true;
      }
    }

    $( "#dialog-form" ).dialog({
      autoOpen: false,
      height: 600,
      width: 500,
      modal: true,
      buttons: {
        "edit": function() {
          var bValid = true;
          allFields.removeClass( "ui-state-error" );
 bValid = bValid && checkLength( box, "box", 1, 16 );
  bValid = bValid && checkLength( itemname, "itemname", 1, 16 );         
  bValid = bValid && checkLength( size, "size", 1, 16 );       
 bValid = bValid && checkLength( potency, "potency", 1, 16 ); 
   bValid = bValid && checkLength( quantity, "quantity", 1, 16 );        

          if ( bValid ) {
            $( "#users tbody" ).append( "<tr>" +
              "<td>" + box.val() + "</td>" +
              "<td>" + itemname.val() + "</td>" +
              "<td>" + size.val() + "</td>" +
              "<td>" + potency.val() + "</td>" +
              "<td>" + quantity.val() + "</td>" +
            "</tr>" );
            $( this ).dialog( "close" );
          }
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      },
      close: function() {
        allFields.val( "" ).removeClass( "ui-state-error" );
      }
    });
};

            if (response.length > 0) {  
            var wrapperelement = document.getElementById('display');

                wrapperelement.innerHTML = response; 
                $("#dialog-form").dialog(opt).dialog("open");

            }
        }
 });

});



 });

</script>

任何想法?谢谢你的时间..

1 个答案:

答案 0 :(得分:1)

你的语法错了。您正在创建一个javascript对象,其语法为:

var opt = {
    box: $( "#box" ),
    itemname: $( "#itemname" ),
    size: $( "#size" ),
    potency: $( "#potency" ),
    quantity: $( "#quantity" ),
    .
    .
}

此外,不需要varbox

你也可以这样做:

var opt = new Object();
opt.box = $( "#box" );
opt.itemname: $( "#itemname" );
.
.