-1

如果有第二个标志如何切断第二个标志?有时 id 是 ....5a 和 5b,我需要删除 'a' 和 'b'

JS

$(".mieszkanie").click(function() {
        var num = this.id.replace(/c_10_0/, "");
        var n = num.length;
        if (n = 2) { 
            [than cut second sign]
        }
        $('.pdf').attr({ 
            href: "img/rzuty/mieszkania/pietro10rzuty/00" + num + ".pdf"
        });
        $('.karta img').attr({ 
            src: "img/rzuty/mieszkania/pietro10rzuty/00" + num + ".png",
            alt: "mieszkanie 00" + num
        });
    });

HTML

<div id="rzuty10p" class="rzuty">
            <span id="c_10_01" class="mieszkanie" title=""></span>
            <span id="c_10_02" class="mieszkanie" title=""></span>
            <span id="c_10_03" class="mieszkanie" title=""></span>
            <span id="c_10_04" class="mieszkanie" title=""></span>
            <span id="c_10_06" class="mieszkanie" title=""></span>
            <span id="c_10_05a" class="mieszkanie" title=""></span>
            <span id="c_10_05b" class="mieszkanie" title=""></span>
        </div>
4

1 回答 1

2

您可以使用该substr方法仅获取第一个字符:

var num = this.id.replace(/c_10_0/, "").substr(0, 1);
于 2012-08-13T14:11:01.410 回答