したがって、ASP.NET ページに以下の小さな数字があります。
このページは、私が満足しているグリッドビューで構成されています。各行にチェックボックスがあり、チェックすると行の他のコントロールが有効になり、保存ボタンは行とアクションをデータベースに繰り返します。
私の質問は、以下のコードは私が望むように機能しますが、さらに単純化するための巧妙なトリックはありますか? 私の知識を広げるためにもっと質問がありますか?:)
`<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>
どうもありがとう、オリー