English 中文(简体)
通过与 Java字功能的联系
原标题:Passing a link to a Javascript function

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...

最佳回答

建立这一职能:

function check_mod($target){
    $target.css({
        "background-color": "#9dc6f4",
        "color":"#fff"
    })
    .find(":checkbox").attr( checked , true);
}

and than use like this:

check_mod($( .inside_border a.task_mod ));
问题回答

粪肥

$( .inside_border a. +class+ :checkbox )

可以通过<代码>$(该数值)[0] 分类。 姓名:。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签