我有一个gridview cotrol,它是[使用c#从数据库填充。来源是
<asp:GridView ID="grdAddressbook" runat="server" AutoGenerateColumns="False" width="100%" Border="0px" cellspacing="0" cellpadding="0">
<Columns>
<asp:TemplateField HeaderText="Name" ItemStyle-Width="27%">
<ItemTemplate>
<asp:Label ID="lblName" runat="Server" Text='<%# Eval("Name") %>' Style="cursor: pointer; display: block;"
onclick="SelectAddressRow(this)"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email Address" ItemStyle-Width="40%">
<ItemTemplate>
<asp:Label ID="lblEmailId" runat="server" ToolTip='<%# Eval("EmailId") %>' Text='<%# Convert.IsDBNull (Eval("EmailId")) ? "" : ( ((String)Eval("EmailId")).Length >25 ? ((String)Eval("EmailId")).Substring(0,25) + "..." :((String)Eval("EmailId"))) %>'
Style="cursor: pointer; display: block;" onclick="SelectAddressRow(this)"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Organization" ItemStyle-Width="33%">
<ItemTemplate>
<asp:Label ID="lblOrganization" runat="server" Text='<%# Convert.IsDBNull (Eval("Organization")) ? " " : ((String)Eval("Organization")) == "" ? " " : Eval("Organization") %>'
Style="cursor: pointer; display: block;" onclick="SelectAddressRow(this)"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我想制作点击红色的特定行的背景。我有一个javascript函数
function SelectAddressRow(column) {
$($(column).parent()).parent().css({ "background-color": "red" });
}
源像这样
后出现<tbody>
<tr>
<th scope="col">Name</th>
<th scope="col">Email Address</th>
<th scope="col">Organization</th>
</tr>
<tr>
<td style="width:27%;">
<span id="grdAddressbook_ctl02_lblName" style="cursor: pointer; display: block;" onclick="SelectAddressRow(this)">ajish</span>
</td>
<td style="width:40%;">
<span id="grdAddressbook_ctl02_lblEmailId" style="cursor: pointer; display: block;" onclick="SelectAddressRow(this)" title="ajish@yahoo.com">ajish@yahoo.com</span>
</td>
<td style="width:33%;">
<span id="grdAddressbook_ctl02_lblOrganization" style="cursor: pointer; display: block;" onclick="SelectAddressRow(this)"> </span>
</td>
</tr>
</tbody>
但是当我点击该行时,一个错误就是在firebug中显示</ p>
ReferenceError: $ is not defined
$($(column).parent()).parent().css({ "background-color": "red" });
答案 0 :(得分:2)
<强> 1。第一强>
检查是否引用了Jquery脚本。
<强> 2。第二强>
如果是,则检查jQuery Conflict。并尝试使用'jQuery'而不是'$'