2014-07-16 6 views
-1

내 html 파일에 GUP 기능을 사용하고 있습니다 :함수는 어떻게 정의합니까?

HTML

<div id="selectPort"> 
    <label id="msgForNonICD"> 
     Select a port to view its ICD details 
    </label> 
</div> 
<script src='dojoroot/dojo/dojo.js'></script> 

자바 스크립트

var nodeLabel = gup('nodeLabel'); 
console.log("printing nodeLabel"+nodeLabel); 

이 오류가 발생합니다 : gup not defined. 이 함수를 어떻게 정의해야합니까?

+0

관련 : index.html을에서

// This code is based on the snipplr referenced in this answer var gup = function(name) { var results = ( new RegExp("[\\?&]"+name+"=([^&#]*)") ).exec(window.location.href); if (results == null) { return ""; } else { return results[1]; } }; 

JavaScript 함수를 정의하는 다양한 방법에 대한 질문 : http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname –

답변

0

:

당신은 아마 그것을 정의하고 오류를 해결합니다. 여기서 "URL 매개 변수 가져 오기"기능에 대해 이야기하고 있다고 가정합니다. 아마도 like the one defined here입니다. 내가하는 일에 대해 틀렸다면, 당신은 여전히 ​​당신이 필요한 모든 기능에이 대답을 적용 할 수 있습니다.

Dojo 툴킷을 사용하려고합니다. 그러나 Dojo에는 "gup"기능이 없으며 바닐라 JavaScript에도 JavaScript가 없으므로 직접 정의해야합니다. 함수에 대한 코드를 파일에 붙여 넣거나 HTML에 다른 <script> 태그를 사용하여 참조하십시오. 자바 스크립트 파일이 HTML 파일과 같은 디렉토리에있는 경우, 결과는 다음과 같습니다

gup.js에서 :

<!DOCTYPE html> 
<html> 
<body> 
<div id="selectPort"><label id="msgForNonICD">Select a port to view its ICD details</div> 
<script src='gup.js'></script> 
<script src='dojoroot/dojo/dojo.js'></script> 
<script type="text/javascript"> 
var nodeLabel = gup('nodeLabel'); 
console.log("printing nodeLabel"+nodeLabel); 
</script> 
</body> 
</html> 
3

I'm getting gup not defined

왜이 오류가 발생하는 가장 분명한 이유는 gup 기능을 정의하지 않았다는 것입니다. 나는 "GUP"기능이 무엇인지 모르는

function gup(string) { 
//your logic here 
} 
관련 문제