2012-07-02 2 views
0

변수에 href 속성을 지정하는 jquery 코드를 만들었습니다. 그 코드는 다음과 같습니다.변수가 아닌 정의되지 않은 변수 오류

$('#reactions' + i).attr('href', 'javascript:comments ('+entry.url+','+i+');'); 

이것은 javascript 함수 주석에 대한 호출을 할당해야합니다.

document.write('<a href="#" id="reactions' + i + '" data-role="button" class="ui-btn-right">Reactions</a>'); 

을하지만이 일을하는 것은 FF와 크롬 나를을 제공 : 지금은 같이, JQuery와 모바일 버튼이 전화를 사용하고 싶습니다. 이것은 FF에서 에러가 이것으로

Uncaught exception: ReferenceError: Undefined variable: i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what Error thrown at line 1, column 0 in javascript:comments (i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what,1);: comments (i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what,1);

, i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_whatentry.url의 값은 ±이다.

나는이 오류가 나타나는 이유를 알지 못한다. 모든 것이 제대로 작동해야한다. 내 것과 비슷한 질문이 있다는 것을 알고 있지만 답을 이해할 수 없습니다. 전체 소스를보고 싶다면 here입니다. 따옴표

답변

3

서라운드 entry.url : 문제를 해결하기 위해

$('#reactions' + i).attr('href', 'javascript:comments ("'+entry.url+'",'+i+');'); 
0

가장 좋은 방법은 그것에게 "jQuery를 방법"을하는 것입니다. 대신 자바 스크립트를 실행하는 href 속성을 추가, 클릭 이벤트를 추가

$('#reactions' + i).click(function() { 
    comments(entry.url, i); 
}); 

마찬가지로 document.write()를 사용하지만 jQuery를 기능을 사용하여 문서에 요소를 추가하지 마십시오.

관련 문제