1

フィールドに属性を挿入し、ユーザーがフィールドの選択を解除したときに属性を削除できるJavaScriptが必要です。

ラジオセレクトに使用しているコードは次のとおりです。

<script>
$(document).ready(function() {
    $("input[name$='sel']").click(function() {
        var test = $(this).val();

        $("div.desc").hide();
        $("#sel" + test).show();
    });

    if (test == "CreditCard") {
        $("#card").addClass("validate[custom[card]] text-input");
    } else {
        $("#card).removeClass("validate[custom[card]] text-input");
    }
});
</script>

フィールドコード:

<table><tr><td>

<p>
Credit/Debit Card<lable  style="margin-right:1px;"></lable><input type="radio" name="sel" id="sel"  value="CreditCard" />
</p> 
<p>
Paypal<input type="radio" id="sel"  name="sel" value="Paypal"   />
</p>
<p>
Wire Transfer<input type="radio" id="sel"  name="sel" value="WireTransfer"  />
</p>
<!====================================================================================>
</td><td>
<!====================================================================================>
<div id="selCreditCard" class="desc">

<label for="card"><strong>Card Number<font color=red size=3> *</font></strong></label>
        <input name="card"   type="text"  id="card" value=""  style="width:85px;" />  
</div>
<!====================================================================================>
<div id="selPaypal" class="desc" style="display: none;margin-left:20px;margin-top:1px;margin-bottom:1px;">
    paypal
</div>
<!====================================================================================>
<div id="selWireTransfer" class="desc" style="display: none;margin-left:20px;margin-top:0px;margin-bottom:-5px;">

Transfer

</div>
<!====================================================================================>
</td></tr></table>
​

これは、「カード」入力フィールドに挿入する必要のある属性です。

class="validate[custom[card]] text-input"

ユーザーが値を持つラジオを選択するとCreditCard、属性が入力フィールドに挿入され、ユーザーが値を持つラジオの選択を解除するとCreditCard、属性が削除されます。

フィドルへのリンク: FIDDLE

4

1 に答える 1

0

テレクパー、あなたのコードには間違ったことがたくさんあります、そして残念ながら私は今説明する時間がありません。

しかし、私はここにあなたのために働くコードを残します:http: //jsfiddle.net/RASG/DSrLS/

「クレジット/デビットカード」をクリックするだけで、クラスnowitsaddedが入力フィールドに追加され、赤に変わります。

HTML

<input type="radio" id="sel1" name="sel"> Credit/Debit Card

<br>

<input type="radio" id="sel2" name="sel"> Paypal

<br>

<input type="radio" id="sel3" name="sel"> Wire Transfer

<br>
<br>

<div id="selCreditCard" class="desc">
    Card Number <input name="card" type="text" id="card" value="">
</div>

JS

$('#sel1').click(function() { $('#card').addClass('nowitsadded') })

CSS

.nowitsadded {background-color: red}
于 2012-09-24T01:40:08.327 に答える