0
我遇到了一个奇怪的情况。我无法启用连续的复选框。使用jquery在gridview中启用禁用的复选框
目前我在,我想成为一个查看文档时启用一个GridView一个TemplateField复选框..
<asp:HyperLinkField DataNavigateUrlFormatString="/documents/{0}" DataNavigateUrlFields="document_name"
Text="View" Target="_blank" >
<ItemStyle HorizontalAlign="Center" />
</asp:HyperLinkField>
<asp:TemplateField HeaderText="Complete" SortExpression="complete">
<ItemTemplate>
<asp:CheckBox ID="gv5cbComplete" runat="server" Checked='<%# Convert.ToBoolean(Eval("complete")) %>'
OnCheckedChanged="GridView5_OnCheckedChanged" AutoPostBack="True" Enabled="False" />
</ItemTemplate>
</asp:TemplateField>
后面的代码中,我通过添加一个onclick事件到HyperLinkField字段一排排倒数。
string cbid = e.Row.Cells[7].ClientID.ToString();
((HyperLink)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "enableGV5CheckBoxFunc(\"" + cbid + "\")");
而且我已经从后面的代码注册了一个javascript jquery函数。
// register script
StringBuilder cstext = new StringBuilder();
cstext.Append("<script type=\"text/javascript\">" + Environment.NewLine);
cstext.Append("function enableGV5CheckBoxFunc(id){" + Environment.NewLine);
cstext.Append("window.alert(id);" + Environment.NewLine);
//cstext.Append("$(\"#\" + id).removeAttr(\"disabled\");" + Environment.NewLine);
cstext.Append("$(\"#\" + id).prop(\"disabled\", false);" + Environment.NewLine);
cstext.Append("}</script>");
cs.RegisterClientScriptBlock(cstype, csname1, cstext.ToString(), false);
现在我知道这是相反的。如果复选框已启用,并且在jquery中设置.prop(禁用,true),那么当我单击超链接时,它将禁用复选框。然而,试图做我想做的事情是行不通的。
是否有某种特定的方式需要我这样做?
尝试'.removeAttr('disabled')' – Ted
@Ted已被注释掉。但是我确实删除了这个测试,并且它没有改变。 – Prescient
它正确地提醒身份证?开头没有'#'?只需签入。完全侧面的说明,出于好奇,为什么不把它放在页面上,而不是放在代码后面呢? – Ted