检索this.title属性的前2个字符,并调用相应的id

时间:2012-01-25 16:10:35

标签: jquery

我正在尝试检索链接的title属性的前两个字符,将其存储到变量中,然后将该变量作为函数调用。在代码中,它显示"#" + s,是我希望放置该值的位置。有任何想法吗?

$(".flow").click(function() {
    if (labelstatus = 1) {
        $('.rmflow a,.weflow a,.scflow a,.coflow a,.wcflow a').css({
            color: "#b7b7b7"
        });

        $("." + this.title + " a").css({
            color: "#3e3e3e"
        });

        $("#" + this.title).parent().animate({
            opacity: '1'
        });

        $('.initiate').animate({
            opacity: '.4'
        }, 100);

        // variable to be put in the below selector
        $("#" + s).parent().animate({
            opacity: '1'
        });

        $('.info').fadeOut(200);
        $("#" + this.title).fadeIn(1000);
        return false;
    }
    else {
    }
});

2 个答案:

答案 0 :(得分:13)

获取标题中的前2个字符: var s = $(this).attr("title").substr(0, 2);

答案 1 :(得分:2)

获取属性的前两个并根据它找到目标。

$('.flow').click(function() {
    var first2 = $(this).attr('customatt').substr(0, 2);
    $('#' + first2).doSomething();
    return false;
});
相关问题