0

我正在尝试向 jquery 对话框添加一些文本,但我无法使用一些文本来初始化字段。这是html的一部分:

<div id="dialog-form-obiectEd" title="Create new userdasdasdasd">
  <p class="validateTips">All form fields are required.</p>

  <form>    
  <fieldset>
    <label for="nameOE">Nume</label>
    <input type="text" name="nameOE" id="nameOE" class="text ui-widget-content ui-corner-all" />
    <label for="descriereOE">Descriere</label>
    <input type="text" name="descriereOE" id="descriereOE" value="" class="text ui-widget-content ui-corner-all" />
    <label for="proprietatiOE">Proprietati</label>
    <input type="text" name="proprietatiOE" id="proprietatiOE" value="" class="text ui-widget-content ui-corner-all" />
  </fieldset>
  </form>
</div>

这是我在单击图像时调用的函数:

function openItem(obiect){

$('#nameOE').empty();
$('#nameOE').text("some value");


$( "#dialog-form-obiectEd" ).dialog( "open" );

reparaZindex();
}

对话框是这样的:

$(function() {
    var name = $( "#nameOE" ),
      descriere = $( "#descriereOE" ),
      proprietati = $( "#proprietatiOE" ),
      allFields = $( [] ).add( name ).add( descriere ).add( proprietati ),
      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( "ui-state-error" );
        updateTips( n );
        return false;
      } else {
        return true;
      }
    }

    $( "#dialog-form-obiectEd" ).dialog({


      autoOpen: false,
      height: 400,
      width: 400,
      modal: true,
      buttons: {
        "Create an account": function() {

          var bValid = true;
          allFields.removeClass( "ui-state-error" );

          bValid = bValid && checkLength( name, "nume", 1, 100 );
          bValid = bValid && checkLength( descriere, "descriere", 1, 100 );
          bValid = bValid && checkLength( proprietati, "proprietati", 4, 100 );

          bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
          // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
          bValid = bValid && checkRegexp( descriere, /^[a-z]([0-9a-z_ \ ])+$/i, "eg. ui@jquery.com" );
          bValid = bValid && checkRegexp( proprietati, /^(([0-9a-zA-Z!\?])+\:([0-9a-zA-Z!\?])+\,?)+$/, "Descrierile trebuie sa contina doar litere si cifre ,:!?, separate prin punct si virgula" );

          if ( bValid ) {

        /////////////////////


        editItem(name.val(),descriere.val(),proprietati.val());


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

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

我希望在打开对话框时用一些字符串填充 nameOE。

4

1 回答 1

1

代替 ...

$('#nameOE').empty();
$('#nameOE').text("some value");

... 和 ...

$('#nameOE').val("some value");

...因为它是一个输入,并且您想要更新它的value,而不是它的文本内容。

于 2013-06-04T22:52:54.280 回答