我有一个从GridView
生成的表,定义如下:
<div>
<table cellspacing="0" id="MainContent_GridView1" style="border-collapse:collapse;">
<tr>
<th scope="col"><a href="javascript:__doPostBack('ctl00$MainContent$GridView1','Sort$CustID')">Customer ID</a></th><th scope="col"><a href="javascript:__doPostBack('ctl00$MainContent$GridView1','Sort$CustFirstName')">First Name</a></th><th scope="col"><a href="javascript:__doPostBack('ctl00$MainContent$GridView1','Sort$CustLastName')">Last Name</a></th><th scope="col"><a href="javascript:__doPostBack('ctl00$MainContent$GridView1','Sort$CustCity')">City</a></th><th scope="col">Email</th>
</tr><tr>
<td>
<span id="MainContent_GridView1_lblCustID_0">12</span>
</td><td>
<span id="MainContent_GridView1_lblFirstName_0">Anders</span>
</td><td>
<span id="MainContent_GridView1_lblLastName_0">Rohansen</span>
</td><td>
<span id="MainContent_GridView1_lblCity_0">Takoma Park</span>
</td><td>
<input name="ctl00$MainContent$GridView1$ctl02$txtEmail" type="text" value="[email protected]" id="MainContent_GridView1_txtEmail_0" />
<span data-val-controltovalidate="MainContent_GridView1_txtEmail_0" data-val-errormessage="Must enter Email Address" data-val-validationGroup="grpEmail" id="MainContent_GridView1_ctl00_0" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="visibility:hidden;">Must enter Email Address</span>
<input type="submit" name="ctl00$MainContent$GridView1$ctl02$btnUpdate" value="Update Email" onclick="return ValidateEmail(this);WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$GridView1$ctl02$btnUpdate", "", true, "grpEmail", "", false, false))" id="MainContent_GridView1_btnUpdate_0" ButtonType="Button" />
</td>
</tr><tr style="background-color:#EEEEEE;">
<td>
<span id="MainContent_GridView1_lblCustID_1">8</span>
</td><td>
<span id="MainContent_GridView1_lblFirstName_1">Deborah</span>
</td><td>
<span id="MainContent_GridView1_lblLastName_1">Damien</span>
</td><td>
<span id="MainContent_GridView1_lblCity_1">Fresno</span>
</td><td>
<input name="ctl00$MainContent$GridView1$ctl03$txtEmail" type="text" value="[email protected]" id="MainContent_GridView1_txtEmail_1" />
<span data-val-controltovalidate="MainContent_GridView1_txtEmail_1" data-val-errormessage="Must enter Email Address" data-val-validationGroup="grpEmail" id="MainContent_GridView1_ctl00_1" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="visibility:hidden;">Must enter Email Address</span>
<input type="submit" name="ctl00$MainContent$GridView1$ctl03$btnUpdate" value="Update Email" onclick="return ValidateEmail(this);WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$GridView1$ctl03$btnUpdate", "", true, "grpEmail", "", false, false))" id="MainContent_GridView1_btnUpdate_1" ButtonType="Button" />
</td>
</tr><tr>
<td>
<span id="MainContent_GridView1_lblCustID_2">7</span>
</td><td>
<span id="MainContent_GridView1_lblFirstName_2">Derek</span>
</td><td>
<span id="MainContent_GridView1_lblLastName_2">Chaddick</span>
</td><td>
<span id="MainContent_GridView1_lblCity_2">Fairfield</span>
</td><td>
<input name="ctl00$MainContent$GridView1$ctl04$txtEmail" type="text" value="[email protected]" id="MainContent_GridView1_txtEmail_2" />
<span data-val-controltovalidate="MainContent_GridView1_txtEmail_2" data-val-errormessage="Must enter Email Address" data-val-validationGroup="grpEmail" id="MainContent_GridView1_ctl00_2" data-val="true" data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val-initialvalue="" style="visibility:hidden;">Must enter Email Address</span>
<input type="submit" name="ctl00$MainContent$GridView1$ctl04$btnUpdate" value="Update Email" onclick="return ValidateEmail(this);WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$GridView1$ctl04$btnUpdate", "", true, "grpEmail", "", false, false))" id="MainContent_GridView1_btnUpdate_2" ButtonType="Button" />
</td>
</tr>
</table>
验证电子邮件字段时,我要突出显示电子邮件文本字段或将其边框设置为红色。在我的
ValidateEmail(btnObj)
函数中执行此操作时$(btnObj).siblings('input:name').style.borderColor="red";
我收到一个错误:“错误:语法错误,无法识别的表达式:语法错误,无法识别的表达式:名称”。
我可以通过
(btnObj).siblings('input:text').val()
访问文本字段什么是正确的方法?
谢谢
最佳答案
您可以使用jQuery通过以下方式更改CSS值:
.css("border", "1px solid red")
您还可以通过类型轻松选择所需的元素
$(btnObj).siblings('input[type="text"]').css("border", "1px solid red");