jquery - 将 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!");
}
});
});
解决方案
为什么不尝试使用溢出隐藏它:隐藏。
下面是一个例子,
.span100p {
display: block;
width: 100px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
<span class="span100p ">Hello world this is a long sentence</span>
有什么需要请回复...
推荐阅读
- html - 使用 CSS 创建下拉菜单时遇到问题
- git - 对master应用hotfix是否与神器中的神器提升实践相矛盾?
- sql - 连接两个事实表(F4801 和 F4111)
- php - 表单提交时模态关闭的纠正建议
- regex - SED - 需要简单的正则表达式
- python - 阶乘矩和下降阶乘
- javascript - ul 列表中的第一个和最后一个 VISIBLE 元素
- javascript - 为什么这个 document.getElementById().value() 在我的 php 中不起作用?
- python - Python3:如何获得用户的重复响应并再次运行循环
- android - 像 ImageView scaleType="fitCenter" 一样缩放背景