클릭 한 링크 된 경로를 다른 링크와 일치 시키려고합니다. 그것은 전혀 작동하지 않습니다. 여기에 코드가 있습니다. href starts with the regex를 링크해야합니다.정규 표현식 값이 jquery와 일치하지 않습니다.
$('#taxonomylist ul li a').click(function() {
$href = $(this).attr("href");
$regex = new RegExp("^"+$href);
$('#taxonomylist ul li').each(function() {
$href_sub = $("a", this).attr("href");
if ($href_sub.match($regex))
{
$(this).css("display", "block");
}
});
return false;
});
는 여기에 내가 불을 지르고에있어 무엇 :
$href = "/?q=category/activity/test"
$href_sub = "/?q=category/activity/test/lamp"
$regex = /^\/?q=category\/activity\/test/
모든 찾을 보이지만, 예상대로 작동하지 않습니다. regex에 의한 일치를 제거하면 모든 것이 잘 작동합니다 (필터링 없이는).
편집 :
지금은 부분적으로 작동이 만 모든 링크에 CSS 속성을 할당 할뿐만 아니라 값과 일치하는. 누구든지 문제가 보이나요? 정규식 당신의 문자열과 일치 경우
$('#taxonomylist ul li a').click(function() {
$href = $(this).attr("href");
$regex = new RegExp("^"+$href);
$('#taxonomylist ul li').each(function() {
$href_sub = $("a", this).attr("href");
if ('$href_sub:contains($href)')
{
$(this).css("display", "block");
}
});
return false;
});
도움이되기를 바랍니다. 대신에'.indexOf'를 사용하십시오. –