Jquery对话框给出属性id后缺失:错误

jquery dialog gives missing : after property id error

本文关键字:错误 id 对话框 属性 Jquery      更新时间:2023-09-26

我试图在这里弹出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>

任何想法?

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

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

也不需要box前面的var

你也可以这样做:

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