2014-03-31 67 views
-1

我有GridView呈现一个表。该表格具有文本字段和输入字段。如何禁用焦点上的特定输入字段?

我写了以下jQuery禁用焦点文本字段。它工作正常:

$(function(){ 

    $('input[type="text"]').live("focus", function() { 
     var rowId = $(this).attr('id'); 
     var inputField = $(this).attr('name'); 
     alert(inputField.indexOf('txtSearchValue')); 
     $('tr').each(function(){ 
      var inputId = $(this).find('input[type="text"]').attr('id'); 
      var submitId = $(this).closest("tr").find('input[type="submit"]').attr('id'); 
      if(inputId != null && typeof inputId !== "undefined"){ 
       if(rowId !== inputId){    
        $(this).find('input[type="text"]').attr("disabled", "disabled"); 
        $(this).closest("tr").find('input[type="submit"]').attr("disabled","disabled"); 
       } 
      } 
     });         
    }); 
}); 

我也有另一个文本字段,不是生成的表的一部分,但它也被禁用我点击属于该表的文本框每次。

这是一个文本字段:

<input id="ctl00_ContentMain_txtSearchValue" type="text" value="2222" name="ctl00$ContentMain$txtSearchValue"></input> 

我试图使用方法:

var inputField = $(this).attr('name'); inputField.indexOf('txtSearchValue');

访问额外的领域,但我不知道如何将其联合我的jQuery,以确保它始终启用。

任何想法?

如何修改它,因此,额外的场

这是我的HTML表格:

<TABLE style="POSITION: absolute; BORDER-BOTTOM-COLOR: red; BORDER-TOP-COLOR: red; BORDER-COLLAPSE: collapse; BORDER-RIGHT-COLOR: red; BORDER-LEFT-COLOR: red; TOP: 150px" id=ctl00_ContentMain_grvIsoSearchResults class=DataWebControlStyle border=1 rules=all cellSpacing=0> 
<TBODY> 
<TR class=HeaderStyle> 
<TH scope=col>ISONUM</TH> 
<TH scope=col>OFFICE NAME</TH> 
<TH scope=col>REGION</TH> 
<TH scope=col>DIVISION</TH> 
<TH scope=col>EMAIL ADDRESS</TH></TR> 
<TR class=RowStyle> 
    <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 70px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl02_txtgvIsoNum>222222222 </SPAN> 
    </TD> 
    <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 200px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl02_txtgvIsoOfficeName>Test, Eugene Test </SPAN> 
    </TD> 
    <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 50px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl02_txtgvRegion>99</SPAN> 
    </TD> 
     <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 50px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl02_txtgvDivision>11111</SPAN> 
     </TD> 
     <TD><INPUT id=ctl00_ContentMain_grvIsoSearchResults_ctl02_txtgvEmailAddress class=textInput name=ctl00$ContentMain$grvIsoSearchResults$ctl02$txtgvEmailAddress [email protected]> 
      <INPUT id=ctl00_ContentMain_grvIsoSearchResults_ctl02_btnEmailUpdate onclick="return ValidateEmail(this);" name=ctl00$ContentMain$grvIsoSearchResults$ctl02$btnEmailUpdate value=Update type=submit> 
     </TD> 
     </TR> 
     <TR class=AlternatingRowStyle> 
     <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 70px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl03_txtgvIsoNum>CB2222001 </SPAN> 
     </TD> 
     <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 200px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl03_txtgvIsoOfficeName>DENNIS PETROVIC </SPAN> 
     </TD> 
     <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 50px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl03_txtgvRegion></SPAN> 
     </TD> 
     <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 50px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl03_txtgvDivision>99801</SPAN> 
     </TD> 
     <TD> 
     <INPUT id=ctl00_ContentMain_grvIsoSearchResults_ctl03_txtgvEmailAddress class=textInput name=ctl00$ContentMain$grvIsoSearchResults$ctl03$txtgvEmailAddress [email protected]> 
      <INPUT id=ctl00_ContentMain_grvIsoSearchResults_ctl03_btnEmailUpdate onclick="return ValidateEmail(this);" name=ctl00$ContentMain$grvIsoSearchResults$ctl03$btnEmailUpdate value=Update type=submit> 
     </TD> 
    </TR> 
    <TR class=RowStyle> 
     <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 70px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl04_txtgvIsoNum>FT2222001 </SPAN> 
     </TD> 
     <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 200px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl04_txtgvIsoOfficeName>DENNIS PETROVIC </SPAN> 
     </TD> 
     <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 50px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl04_txtgvRegion></SPAN> 
     </TD> 
     <TD><SPAN style="TEXT-ALIGN: center; WIDTH: 50px; DISPLAY: inline-block" id=ctl00_ContentMain_grvIsoSearchResults_ctl04_txtgvDivision>99801</SPAN> 
     </TD> 
     <TD><INPUT id=ctl00_ContentMain_grvIsoSearchResults_ctl04_txtgvEmailAddress class=textInput name=ctl00$ContentMain$grvIsoSearchResults$ctl04$txtgvEmailAddress [email protected]> 
     <INPUT id=ctl00_ContentMain_grvIsoSearchResults_ctl04_btnEmailUpdate onclick="return ValidateEmail(this);" name=ctl00$ContentMain$grvIsoSearchResults$ctl04$btnEmailUpdate value=Update type=submit> 
     </TD> 
    </TR> 
</TBODY> 
</TABLE> 
+0

如果您发现我的答案有用,请接受它作为正确答案。 – Pio

回答

0

您连接到所有'input[type="text"]'功能。这意味着您网页上的所有输入字段将具有此功能。您可能想查看this的问题。

您的查询应该看起来像这样:table > input[type="text"]For more details。在你的代码

UPDATE

寻找我不知道你的系统没有你真正想要的。无论如何,这里是一个filldle,它为您提供表格中inputText类的字段。然后你可以附加一个功能(只需弹出控制台 - 在Chrome F12中,你会看到页面的选定元素)。

正如我所说的,你需要按级别来限制你的选择级别:

$('td > .textInput').each(function(){ 
    console.log(this); 
}) 

所以,你选择所有所有td标签.textInput类。这将工作,而不是只有uwing $('.textInput'),以防您没有任何其他td标签。如果您有多个表,则使用您希望在选择器中使用的表的ID,然后从那里下降到所需的级别。

+0

当我将'focus'事件附加到我的输入时,我可以使用'not'过滤器吗?像'$('input [type =“text”]')。not(“[name ='value']”)。live ... –

+0

呃...你有代码就试试吧。但理想情况下,您将使用“子选择器”限制选择器。 – Pio

+0

说实话,我对jQuery和新鲜事很陌生,很难理解我需要做些什么来使某些事情适合我...... :)谢谢 –