누군가 도움을 줄 수 있기를 바랍니다.동적으로 href를 변경하고 URL 조각에 연결
<a class="resourceLink" href="" title="Link to Resources section" target="_blank">Resources</a>
:이 같은 몇 가지 링크를 사용하고있어 HTML에서
$(document).ready(function(){
if (document.location.pathname.indexOf('cab2') > -1){
document.getElementsByClassName('resourceLink').setAttribute('href','http://www.myserver.net/cab2/#linkResources');
} else {
document.getElementByClassName('resourceLink').setAttribute('href','http://www.myserver.net/cab/#linkResources');
};
});
: 동적으로 페이지에하는 HREF를 변경 한 다음과 같은 단편을 포함하는 URL에 사용자를 가리 키도록 노력하고있어
내가 스크립트는 방문자가 사이트에 도달하기 위해 사용했다 url로 내용을 확인할 것이었다 기대했다 하나
- http://www.myserver.net/cab/ 또는, 다음
http://www.myserver.net/cab2/과가 해당하는 HREF를 설정 중 하나를
http://www.myserver.net/cab/#linkResources 또는 http://www.myserver.net/cab2/#linkResources
링크가 기본 페이지 (www.myserver을 열어 무엇입니까하지만 발생
내가 뭘 잘못하고 있니? 관심을 가져 주셔서 감사합니다.
[getElementByClass().의 setAttribute가 작동하지 않습니다]의 사용 가능한 복제 (http://stackoverflow.com/questions/2565909/getelementbyclass -setattribute-doesnt-work) – dave
jQuery를 사용하고 있습니다. – epascarello