アタッチ(表示/非表示テキスト)を動的かつショーをクリックしたときに/以下のフィールドセットを隠します

StackOverflow https://stackoverflow.com/questions/1304180

質問

私は動的スパンに(表示/非表示テキスト)を添付すると、特定のテキストをクリックしたとき、私は、以下のフィールドセットで表示/非表示の効果を持っていると思います。 私はスパンに付加表示/非表示のテキストを持つのタスクをacheived。しかし、問題は、私はそのテキストをクリックしたときに生じます。スパンの横にテキストが変更されます以外何も起こりません。

HTMLます:

<span>Store Dropdown</span>
<fieldset id="fieldset-store" class="showHide">
    <legend>Choose by item:</legend>
    <label for="prodtype">Type:</label>
    <select name="prodtype" id="prodtype">
        <option value="0" selected="selected">Choose type</option>                  
        <option value="1"> Sample1</option>
        <option value="2"> Sample2</option>
        <option value="3"> Sample3</option>
        <option value="4"> Sample4</option>
    </select> 
    <label for="brandtype">of:</label>
    <select name="brandtype" id="brandtype">                
        <option value="0" selected="selected">Choose brand</option>                 
        <option value="1"> Brand1</option>
        <option value="2"> Brand2</option>
        <option value="3"> Brand3</option>
        <option value="4"> Brand4</option>
    </select>
    <label for="prodprice">Price:</label> <input id="prodprice" name="prodprice" value="" type="text">
</fieldset>

JSコード:

$(document).ready(function(){
    $(".showHide").prev().append(' <a href="#" class="showHideLink">Show</a>');
    $(".showHide").hide();
    $('a.showHideLink').click(function() {
        if ($(this).html()=='Show')
            $(this).html('Hide');
        else 
            $(this).html('Show');
        $(this).next().toggle('slow');
        return false;
    });
});

Plsは私が作るために必要なものを変更私を示唆しています。事前に感謝します。

役に立ちましたか?

解決

$(document).ready(function(){
            $(".showHide").prev().append(' <a href="#" class="showHideLink">Show</a>');
            $(".showHide").hide();
            $('a.showHideLink').click(function() {
                if ($(this).html()=='Show')
                        $(this).html('Hide');
                else
                        $(this).html('Show');
                $(".showHide").toggle('slow');
                return false;
            });
        });

または

$(document).ready(function(){
                $(".showHide").prev().append(' <a href="#" class="showHideLink">Show</a>');
                $(".showHide").hide();
                $('a.showHideLink').click(function() {
                    if ($(this).html()=='Show')
                            $(this).html('Hide');
                    else
                            $(this).html('Show');
                    $(this).parent().next().toggle('slow');
                    return false;
                });
            });
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top