可以使用jQuery验证显示和隐藏TR ID元素吗?

时间:2016-08-05 15:14:10

标签: javascript jquery css

我最近在我的一些网络表单中实现了jQuery验证。我正在尝试使用更多的东西,替换了我已经使用了一段时间的旧代码。

我有一种情况,我试图在TR标签上显示和隐藏ID元素。我一直在搜索这个,但我主要是找到我没有使用过的DIV标签的引用,而不是TR标签上的ID元素,我一直在使用它。我的问题基本上是jQuery可以在TR标签上显示和隐藏id元素吗?它看起来并不像我一直想写的东西没用。

我目前的代码就是这里的一种。

    <td colspan="5"><select name="acctloc" id="acctloc" class="inputtxtbox" onChange="msgSwap2a()"  required>
<option value="" selected>Please  select...</option>
<option value="Channel1">Channel 1</option>
<option value="Channel2">Channel 2</option>
<option value="Channel3">Channel 3</option>
<option value="Chan-Cust">Chan-Cust</option>
<option value="Network">Network</option>
<option value="SpecCust">Special Cust</option>
</select>


    <tr id="acctnetwork" style="display:">
    <td align="right"><label for="Acct_num">Acct Number:</label></td>
    <td colspan="5"><input name="Acct_num" type="text" id="Acct_num"  onChange="this.value = new chkLoan(this.value.trim());if (this.value == 'NaN' || this.value.length.trim() <10)  {alert ('That is not a valid Acct #. \n Please enter in format of ##-####-#######.'); this.value = ''; this.focus}" required>
    </td>
    </tr>
    <tr id="acctother" style="display:none">
    <td align="right"><p>Acct Number:-</p></td>
    <td colspan="5"><input name="Acct_num_sec" type="text" onChange="this.value=this.value.trim()" id="Acct_num_sec">
    </td>
    </tr>
    <tr id="specialname" style="display:none">
    <td align="right">Special Acct Name (in lieu of number)</td>
    <td colspan="5"><input name="Acct_num_spec" type="text"  id="Acct_num_spec" onChange="convHeSpec();"></td>
    </tr>
    <tr id="specr" style="display:none">
    <td align="right"></td>
    <td colspan="5" bgcolor="#FF9933" class="pageContentHeading">ATTENTION: For security reasons these  orders for  special accounts must be placed using the customer's last name in the account number box.  When searching vendor website for the order, you must search by account name and address and not account number. </td>
    </tr>

我可以添加代码的其他部分,但它基本上是一个用documentgetElementById显示和隐藏ID元素的块,就像这样。

    if (form.acctloc.value == "Channel1" || form.acctloc.value   == "Channel2" || form.acctloc.value == "Channel3" || form.acctloc.value   == "Chan-Cust" ) { 
    document.getElementById('acctother').style.display='';
    document.getElementById('acct_loc').style.display='none';
    document.getElementById('acctnetwork').style.display='none';
    document.getElementById('specr').style.display='none';
    document.getElementById('specialname').style.display='none';
    document.form.Acct_num.value == '';
    }   

我理解在jQuery中你创建了id元素         $( 'acct_loc') 而不是把整个documentgetElementById放在它前面,但我的主要问题是我需要更改TR ID标签并将它们包装在DIV标签ID元素中吗? 而不是

     <tr id="specialname" style="display:none">

制作

     <div id="specialname" style="display:none">   ?

感谢任何帮助和反馈!

谢谢!

1 个答案:

答案 0 :(得分:0)

隐藏tr而不是div应该没有问题。如果你现在正在使用jquery,请尝试:

    $('#yourElementIDHere').css('display', 'none')

这将更改您选择的任何元素的css属性