从Jquery UI表单获取变量并发布?

时间:2013-08-04 05:04:21

标签: html html5 jquery-ui jquery

我尝试从My表单中获取变量。我的剧本是:

$(function() {
    var title = $ ( "#title" ),
      message= $( "#message" ),
      category = $( "#category" ),

      allFields = $( [] ).add( title ).add( message ).add( category ),
      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( "Length of " + n + " must be between " +
          min + " and " + max + "." );
        return false;
      } else {
        return true;
      }
    }

    function checkRegexp( o, regexp, n ) {
      if ( !( regexp.test( o.val() ) ) ) {
        o.addClass( "error" );
        updateTips( n );
        return false;
      } else {
        return true;
      }
    }

    $( "#dialog-form" ).dialog({
      autoOpen: false,
      height: 600,
      width: 550,
      modal: true,
      buttons: {
        "Create an account": function() {
          var bValid = true;
          allFields.removeClass( "error" );

          bValid = bValid && checkLength( title, "Title", 3, 16 );

          bValid = bValid && checkLength( message, "message", 5, 360 );
          bValid = bValid && checkLength( category, "category", 5, 16 );

          bValid = bValid && checkRegexp( title, /^[a-z]([0-9a-z_])+$/i, "Title may consist of a-z, 0-9, underscores, begin with a letter." );
          bValid = bValid && checkRegexp( message, /^[a-z]([0-9a-z_])+$/i, "Message may consist of a-z, 0-9, underscores, begin with a letter." );
          bValid = bValid && checkRegexp( category, /^[a-z]([0-9a-z_])+$/i, "Category may consist of a-z, 0-9, underscores, begin with a letter." );




          if ( bValid ) {
            $.post("upDate.php",{title: tilte.val(), message: message.val(), categorie: category.val()});


           $( "#users-contain" ).append('<div class="bubble-list">    <div class="bubble clearfix"> <img src="./img.php?message=MY PROFIL PIC" title="'+ title.val()+'"> <div class="bubble-content"> <div class="point"></div><p>' + message.val() +'</p><ul class="tags"><li><a href="#">'+ category.val() +'</a></li></ul></div></div></div>' );


                        $( this ).dialog( "close" );

          }
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      },
      close: function() {
        allFields.val( "" ).removeClass( "ui-state-error" );
      }
    });

    $( "#create-user" )
      .button()
      .click(function() {
        $( "#dialog-form" ).dialog( "open" );
      });
  });

我绑定了一些提醒以查看回调,但也无法正常工作。 我使用的是最后一个版本的jQuery UI,我不知道那里有什么问题。

1 个答案:

答案 0 :(得分:1)

否。 1

为什么不使用.serialize()发帖?这对你来说非常简单,

否。 2

当您传递变量时,代码中有错误(拼写错误)

 $.post("upDate.php",{title: tilte.val(),... //tilte??

应该是

 $.post("upDate.php",{title: title.val(),....