2016-08-05 7 views
1

私は最近、いくつかのWebフォームに対してjQueryのバリデーションを実装しました。私はそれをより多く雇用しようとしています。古いJavaScriptコードを置き換えています。jQueryでTR ID要素を表示および非表示にすることはできますか?

私は、TRタグにID要素を表示して隠そうとしている状況があります。私はこれを検索してきましたが、私は主に私が使用しているTRタグのID要素とは対照的に、私が使用していないDIVタグへの参照を探しています。私の質問は基本的に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> 

Iは、コードの他の部分を追加することができ、それは基本的に、このような、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の中で、あなたがそれの前に全体documentgetElementByIdを置くのではなく、id要素 $(「acct_loc」) を作ることを理解し、私のメインの質問は、私はTRのIDタグを変更する必要がありますです代わりにDIVタグID要素でラップしますか?代わりの

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

同様 は、すべてのヘルプとフィードバックが評価され、それ

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

作ります!

ありがとうございます!

+0

を選択して、私はドキュメントのgetElement部分と一部であることを、私は推測し、追加したはずですどんな要素のCSSプロパティを変更します関数内のmsgSwap2a()。 –

答えて

0

divの代わりにtrを隠すことに問題はありません。あなたは今のjQueryを使用している場合は、やってみてください:

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

これは、あなたが

+0

よろしくお願い致します。また、上記で指定したか明確にしているかどうかはわかりませんが、同様のフィールドを表示すると一部のフィールド値がnullにリセットされます。 このように。 document.getElementById( 'specr')。style.display = 'none'; document.getElementById( 'specialname')。style.display = 'none'; document.form.Acct_num.value == ''; 私はちょうどそれをします $( 'Acct_num')。値= ''; それは正解でしょうか? –

+0

構文は少し異なります。 JQueryでは、通常、メソッド呼び出しの中で値を設定します。たとえば、上記の例では、$( "#Acct_num")。val( '')を使用して、()内の任意の値に値を設定できます。 JQueryのメソッドは一般にオーバーロードされているため、空のままにしておくと値が返されますが、値を含めると値は – Justin

+0

です。ありがとう、Justin! –

関連する問題