[英]show a div class on clicking a link
How do I show a div class on clicking a link?如何在单击链接时显示 div 类?
This is the div class that must be shown:这是必须显示的 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 -->
This div class must be shown when I click any of the links given below:当我单击下面给出的任何链接时,必须显示此 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>
The 'myform' div is shown by default. 'myform' div 默认显示。 how to show the same 'myform' div when I click the link for textarea or checkbox?
当我单击 textarea 或复选框的链接时,如何显示相同的“myform”div?
EDIT: This should do it:编辑:这应该这样做:
$('#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");
});
okay .. i just completed what karim did :好吧..我刚刚完成了卡里姆所做的:
$('#fb_contentarea_col1down a').click(function() {
$('#fb_contentarea_col1down1').show();
// to remove all selected
$('.fb_contentarea_col1down li').attr('class',''); // this will reset all class
// assign the selected class for this link only
var id = $(this).attr('id');
// set selected on the <li>
$('#'+id+':parent').attr('class','selected');
});
You just need to assign an id on each <a> tags
你只需要在每个
<a> tags
上分配一个 id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.