首页 > 解决方案 > 将 maxlenght 添加到文本框

问题描述

一些值从 C# 返回到 ajax。我需要将这些值绑定到 GridView。一切正常,但唯一的区别是这个值:$("span", row).eq(4).attr("maxlength",this.MaxNoPlaces);需要绑定到MaxLength文本框的属性而不是值。

我也尝试过输入而不是 span 和 attrmaxlength但它不起作用。

$(document).on('click', ".myBtn", function() {

  header = $(this).closest('tr').find('.ObjekatID').text()
  console.log(header);


  $.ajax({
    type: "POST",
    url: "Administration.aspx/GetRequest",
    data: JSON.stringify({
      'header2': header2
    }),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data) {
      var row = $("[id*=grdDemo] tr:last-child").clone(true);
      $("[id*=grdDemo] tr").not($("[id*=grdDemo] tr:first-child")).remove();
      //  alert($("[id*=grdDemo]").html());
      var count = 1;
      $.each(data.d, function() {
        $("span", row).eq(0).html(this.ObjectID);
        $("span", row).eq(1).html(this.ObjectName);
        $("span", row).eq(2).html(this.ObjectValue);
        $("span", row).eq(3).html(this.ObjectTypeID);

        $("span", row).eq(4).attr("maxlength", this.MaxNoPlaces);

        $("[id*=grdDemo] tbody").append(row);
        console.log(row);
        if (count == 1 || (count % 2 != 0)) {
          $(row).css("background-color", "rgb(193, 212, 248)");
        } else {
          $(row).css("background-color", "white");
        }
        count = count + 1;
        row = $("[id*=grdDemo] tr:last-child").clone(true);

      });


    },
    error: function() {
      console.log("Not Saved!");
    }

  });

});

标签: jquery

解决方案


为什么不尝试使用溢出隐藏它:隐藏。

下面是一个例子,

 .span100p {
    display: block;
    width: 100px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
   }

<span class="span100p ">Hello world this is a long sentence</span>

有什么需要请回复...


推荐阅读