我正在創建一個程序,其中每個GridView行中都有一個複選框和一個文本框,它們分別未選中和禁用。當勾選複選框時,我需要啓動一些JavaScript來啓用該文本框,反之亦然。到目前爲止,我這樣做:用於GridView行的JavaScript TemplateFields
JS:
<script type="text/javascript">
function onholdev(index) {
var chk = document.getElementById('<%=grdCons.Rows[index].FindControl("chkHold").ClientID %>');
var txt = document.getElementById('<%=grdCons.Rows[index].FindControl("txtReason").ClientID %>');
if (chk.checked == true) {
txt.disabled = false;
}
else {
txt.disabled = true;
txt.value = "";
}
}
</script>
C#(RowDataBound事件)
CheckBox chkHold = ((CheckBox)e.Row.FindControl("chkHold"));
chkHold.Attributes.Add("onchange", "onholdev(" + e.Row.RowIndex + ")");
但在JS,它說的 '索引' 變量不存在,在函數的第一行(以var chk開頭)。我做對了嗎?
感謝哥們,它告訴我'字符串中的字符太多了',儘管 – Chris 2010-11-24 11:54:44