jquery - 单击链接时显示 div 类

标签 jquery css

如何在点击链接时显示 div 类?

这是必须显示的 div 类:

<div id="fb_contentarea_col1down1">
    <div class="myform" id="step2">

        <form action="index.html" method="post" name="FieldSetting" id="FieldSetting">
            <label class="topspace">
                Field Label:
            </label>

            <input id="fieldName" name="fieldName"></input>
            <label class="topspace">
                Field Size:
            </label>

            <select id="fieldSize" name="fieldSize">
                <option>Choose a size </option>
                <option value="small">Small</option>
                <option value="medium">Medium</option>
                <option value="large">Large</option>
            </select>

            <label class="topspace">
                Options:
            </label>

            <input id='required' name="required" type='checkbox'>Required</input>

            <label class="topspace">
                Instruction for User:
            </label>

<textarea cols="40" id="instructions" name="instructions" rows="20" style="width: 98%; height: 70px;"></textarea>
            <br class="clear_both" />
            <input type="submit" class="button" value="Submit" />

        </form>
    </div><!-- End of myform -->
</div><!-- End of fb_contentarea_col1down1 -->

当我单击下面给出的任何链接时,必须显示此 div 类:

<div id="fb_contentarea_col1down">
    <ul class="formfield">
        <li class="selected"><a href="#" id="text">Text</a></li>

        <li><a href="#" id="textarea">Textarea</a></li>

        <li><a href="#" id="checkbox">Checkbox</a></li>
    </ul>
</div>

'myform' div 默认显示。单击文本区域或复选框的链接时如何显示相同的“myform”div?

最佳答案

编辑:应该这样做:

$('#fb_contentarea_col1down a').click(function() {
    $('#fb_contentarea_col1down1').show();

    //find the element in the div with class of selected and remove
    //all classes from it
    $('#fb_contentarea_col1down').find(".selected").removeClass();

    //add the class to the li parent of the clicked anchor
    $(this).parent().addClass("selected");
});

关于jquery - 单击链接时显示 div 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1047449/

相关文章:

jquery - 慢速非 Ajax 页面的假加载/进度条

JQUERY通过单击更改src,然后再更改一次

html - 让 div 中的图像在浏览器调整大小时收缩

javascript - 使用 jquery/ajax 在另一个颜色盒上使用颜色盒

javascript - 显示 : none changes to display: inline by itself?

jquery - 大量使用 AJAX 的页面是否也对搜索引擎友好?

html - CSS float 左奇怪的行为

html - 当 parent 的高度通过 padding-top 设置时设置 child 的高度

javascript - window.location.href 导航出我的网站

css - 如何在 Bootstrap 导航栏中的品牌标签和菜单项之间插入空格