所以我在 ASP.NET 页面上有以下小数字。
该页面包含一个我很满意的gridview,每行都有一个复选框,一旦选中,就会启用行中的其他控件,保存按钮会遍历行和操作进入数据库。
我的问题是,下面的代码按我想要的方式工作,但是有什么巧妙的技巧可以进一步简化吗?更多的问题来扩展我的知识?:)
`<script type="text/javascript">
$(document).ready(function () {
//If checkbox in row is checked then
$('[id^="MainContent_TCProcurement_TABPurchasing_GVQuotes_CBPurchased1_"]').click(function () {
//Checkbox row id
var idstr = this.id.replace('MainContent_TCProcurement_TABPurchasing_GVQuotes_CBPurchased1_', '');
//Controls to alter
var suppDDL = $("#MainContent_TCProcurement_TABPurchasing_GVQuotes_DDLSuppliers_" + idstr);
var qtyPurchased = $("#MainContent_TCProcurement_TABPurchasing_GVQuotes_TBQuantity1_" + idstr);
var ratePaid = $("#MainContent_TCProcurement_TABPurchasing_GVQuotes_TBRatePaid1_" + idstr);
var buyer = $("#MainContent_TCProcurement_TABPurchasing_GVQuotes_TBBuyer1_" + idstr);
var purchasedDate = $("#MainContent_TCProcurement_TABPurchasing_GVQuotes_TBDatePurch1_" + idstr);
//If checked then remove disabled and enter some details
if (this.checked) {
suppDDL.removeAttr('disabled').removeClass('aspNetDisabled').removeAttr("style");
qtyPurchased.removeAttr('disabled').removeClass('aspNetDisabled').removeAttr("style");
ratePaid.removeAttr('disabled').removeClass('aspNetDisabled').removeAttr("style");
buyer.removeAttr('disabled').removeClass('aspNetDisabled').removeAttr("style").val("<%= Session("loggedInUserName")%>");
purchasedDate.removeAttr('disabled').removeClass('aspNetDisabled').removeAttr("style").val("<%= Date.Now()%>");
} else {
var newTBStyle = "font-family: Arial; font-size: 1em; background-color: rgb(235, 235, 228);";
suppDDL.attr('disabled', 'disabled').addClass('aspNetDisabled').attr('style', newTBStyle);
qtyPurchased.attr('disabled', 'disabled').addClass('aspNetDisabled').attr('style', newTBStyle);
ratePaid.attr('disabled', 'disabled').addClass('aspNetDisabled').attr('style', newTBStyle);
buyer.attr('disabled', 'disabled').addClass('aspNetDisabled').attr('style', newTBStyle).val("");
purchasedDate.attr('disabled', 'disabled').addClass('aspNetDisabled').attr('style', newTBStyle).val("");
}
});
});
</script>
非常感谢,奥利