Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

자바스크립트 페이지 넘어가게 하는 법... #89

Closed
G0Dpapa opened this issue Jan 9, 2018 · 4 comments
Closed

자바스크립트 페이지 넘어가게 하는 법... #89

G0Dpapa opened this issue Jan 9, 2018 · 4 comments

Comments

@G0Dpapa
Copy link

G0Dpapa commented Jan 9, 2018

2018-01-09 6 42 21

제가 하고 싶은건 country가 바뀌면 그 country의 웹페이지로 넘어가게 하고 싶은데(Korea를 선택하면 KR.html로 넘어가가도록....) 도저히 모르겠어서 질문을 올립니다

@G0Dpapa G0Dpapa changed the title 페이지 넘어가게 하는 법... 자바페이지 넘어가게 하는 법... Jan 9, 2018
@G0Dpapa G0Dpapa changed the title 자바페이지 넘어가게 하는 법... 자바스크립트 페이지 넘어가게 하는 법... Jan 9, 2018
@egoing
Copy link
Contributor

egoing commented Jan 9, 2018

이런 경우라면 jsfiddle.net 이나 codepen.io 와 같은 서비스를 이용해서 질문해주시면 답변자들이 실시간으로 테스트해보면서 도움을 드리기 쉬울 것 같습니다. 답변을 한번 보강해보셔요~

@ghdalsrldi
Copy link
Collaborator

ghdalsrldi commented Jan 9, 2018

<select id="country" onchange="CountryHandler();">
  <option value="">Country</option>
  <option value="kr">Korea</option>
</select>

onclick 대신에 onchange를 사용하면 좋을 것 같아요

function CountryHandler() {
	alert(); return;
  var x = document.getElementById('country').value;

  // 선택된 country 값이 없다면 이동하지 않는다
  if (!x) {
    return false;
  }

  
  // 선택된 country 페이지로 이동
  window.location.href = x + '.html';

}

@G0Dpapa
Copy link
Author

G0Dpapa commented Jan 9, 2018

@ghdalsrldi
2018-01-10 8 55 48
이렇게 바꿨는데 잘 동작이 안되네요....
어디가 문제인가요..ㅠ

@ghost
Copy link

ghost commented Aug 2, 2018

window.location.herf가 함수 안으로 들어야할 것 같습니다
변수 x가 함수 내부에 선언되어 있어서 밖에서는 접근이 안 되네요

@blackdew blackdew closed this as completed Aug 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants