나는 현재 다음과 같은 자바 스크립트 코드 작업이 있습니다(자바 스크립트) 파일 확장명없이 현재 URL의 마지막 부분을 추출하는 방법은 무엇입니까?
<script type="text/javascript">
urlPath=window.location.pathname;
urlPathArray = urlPath.split('/');
urlPath1=urlPathArray[2];
document.write('<a href="http://www.example.com/contact.php?id='+urlPath1+'">test</a>');
</script>
현재 URL은 자바 스크립트 내가이 스크립트를 수정하려면 어떻게 http://www.example.com/contact.php?id=0033.htm
에 대한 하이퍼 링크를 생성 http://www.example.com/products/0033.htm
말할 수 있습니다를되도록 urlPath1 및 최종 하이퍼 링크에 ".htm"부분이 없습니까?
파일 확장자는 크기가'.htm'입니까? –
'urlPathArray [2];'마지막 요소를 얻기 위해'urlPathArray [urlPathArray.length - 1]'을 사용하십시오 ... –