更改文本框的最大长度值
Changing max length value of textbox
某些值从 C# 返回到 ajax。
我需要将这些值绑定到 GridView。
一切正常,但唯一不同的是这个值:
$("span", 行).eq(4).html(this.MaxNoPlaces);需要绑定到文本框的 MaxLenght 属性 而不是值。
我想我需要使用这个 attr('maxlength') 而不是 html 但我不知道如何。
有人可以帮我解决这个问题吗?
提前致谢!
<script type="text/javascript">
$(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).html(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!");
}
});
});
我想这就是您要找的:
$("span", row).eq(4).attr("maxlength",this.MaxNoPlaces);
某些值从 C# 返回到 ajax。 我需要将这些值绑定到 GridView。 一切正常,但唯一不同的是这个值: $("span", 行).eq(4).html(this.MaxNoPlaces);需要绑定到文本框的 MaxLenght 属性 而不是值。
我想我需要使用这个 attr('maxlength') 而不是 html 但我不知道如何。 有人可以帮我解决这个问题吗?
提前致谢!
<script type="text/javascript">
$(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).html(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!");
}
});
});
我想这就是您要找的:
$("span", row).eq(4).attr("maxlength",this.MaxNoPlaces);