如果有第二个标志,如何切断第二个标志?有时候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>
答案 0 :(得分:2)
您可以使用substr
方法仅获取第一个字符:
var num = this.id.replace(/c_10_0/, "").substr(0, 1);