我要附加(显示/隐藏文本)动态地跨度和该特定文本点击时,我想有下面一个字段显示/隐藏效果。 我来达到的有追加到跨越显示/隐藏文字的任务。但是,当我在该文本上点击就会出现问题。什么也没有发生,除了旁边跨度得到改变的文本。

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