My code works, but I d like to clean it up and possibly reuse it instead of copying it.
我有一套选择的箱子,每个箱子都经过挑选,检查或检查一组基于等级标签的检查箱。
可否将班次名称.task_mod传至以下职能:
$( .inside_border a.task_mod :checkbox ).attr( checked , true);
$( .inside_border a.task_mod ).css("background-color","#9dc6f4");
$( .inside_border a.task_mod ).css("color","#fff");
可适用吗? 这样,我就可以把这一职能用于所有其他检查箱。
检查_mod(链接_mod);
$( [name="workspace_type"] ).change(function()
{
if($(this).val() == "0")
{
$( .inside_border a :checkbox ).attr( checked , false);
$( .inside_border a ).css("background-color","#dfdfdf");
$( .inside_border a ).css("color","#6e6d6d");
}
else if($(this).val() == "small_biz")
{
$( .inside_border a.task_mod :checkbox ).attr( checked , true);
$( .inside_border a.task_mod ).css("background-color","#9dc6f4");
$( .inside_border a.task_mod ).css("color","#fff");
}
});
选择箱
<select name="workspace_type">
<option value="0">select please</option>
<option value="small_biz">Small Business</option>
<option value="freelance">Freelancer</option>
<option value="startup">Startup Company</option>
<option value="small_team">Small Team</option>
<option value="academic">Academic</option>
<option value="media">Media Organization</option>
<option value="personal">Personal</option>
</select>
检查箱
<div class="inside_border">
<a href="#" class="task_mod"><input type="checkbox" name="add_mod"/>Tasks</a>
<a href="#" class="docs_mod"><input type="checkbox" />Documents</a>
<a href="#" class="discuss_mod"><input type="checkbox" />Discussions</a>
<a href="#" class="links_mod"><input type="checkbox" />Links</a>
<a href="#" class="images_mod"><input type="checkbox" />Images</a>
<a href="#" class="customer_mod"><input type="checkbox" />Customers</a>
<a href="#" class="project_mod"><input type="checkbox" />Projects</a>
<a href="#" class="members_mod"><input type="checkbox" />Members</a>
</div>
If you don t understand, I can explain. P.S. I know I should use Id(s) for the checkboxes but...