2014-02-10 3 views
0

이 jQuery 코드를 테스트했지만 실행되지 않았습니다. 콘솔 (F12)을 연 후 테스트 코드를 붙여 넣은 후 완벽하게 컴파일합니다. src = "http://code.jquery.com/jquery-latest.min.js"를 제거하고 $ (document) .ready (function() {경고가 작동하지만 경고 메시지가 나타나면 콘솔에서 메시지 :Jquery/Javascript append가 실행되지 않습니다

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"> 


$(document).ready(function(){  
alert('Hi!'); 
$("#content").append('<div class=\'toolbarBox toolbarHead\' style=\'background-color: #F8F8F8;border: 1px solid #CCCCCC;margin-bottom: 10px;padding: 5px 0;border-radius: 3px;-moz-border-radius: 3px;-webkit-border-radius: 3px;-o-border-radius: 3px;position: relative;\'><div class=\'pageTitle\'><h3 style = \'font-size: 1.6em;font-weight: normal;line-height: 52px;text-shadow: 0 1px 0 #fff;\'><span id=\'current_obj\' style=\'font-weight: normal;\'><span class=\'breadcrumb item-0\'>My Affiliates<img alt=\'&gt;\' style=\'margin-right:5px\' src=\'../img/admin/separator_breadcrumb.png\'></span><span class=\'breadcrumb item-1\'>Affiliates</span></span></h3></div></div>'); 
$("#content").append("<iframe style=\'width: 100%;height: 100%;\' src=\'http://www.myaffiliates.gr/\'></iframe>"); 

}); 

답변

8

스크립트 태그는 다음과 같습니다?. 여기

내 테스트 코드가 어떤 도움을하시기 바랍니다 것입니다 왜 궁금 : "catch되지 않은 ReferenceError가 $가 정의되어 있지 않습니다" 적절하지 않음

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> 
<script type="text/javascript"> 
// your script 
</script> 

script 요소에는 src 또는 본문이 포함될 수 있지만 둘 다 포함될 수는 없습니다.

Script : src

This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a document. script elements with an src attribute specified should not have a script embedded within its tags.

+0

는 당신이 일을 감사합니다! : D 당신의 도움에 감사드립니다! :) – Sergiti

+0

2 개의 스크립트 요소가 필요한 이유를 설명해 주시겠습니까? – Sergiti

+0

@Sergiti는 스크립트 태그가 작동하는 방식이기 때문에 ... src 속성이 지정된 경우 여는 태그와 닫는 태그 사이의 내용이 비어 있어야합니다. - http://javascript.crockford.com/script.html –

0

시도

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> 
<script> 
    $(document).ready(function() { 
     alert('Hi!'); 
     $("#content").append('<div class=\"toolbarBox toolbarHead\" style=\"background-color: #F8F8F8;border: 1px solid #CCCCCC;margin-bottom: 10px;padding: 5px 0;border-radius: 3px;-moz-border-radius: 3px;-webkit-border-radius: 3px;-o-border-radius: 3px;position: relative;\"><div class=\"pageTitle\"><h3 style =\"font-size: 1.6em;font-weight: normal;line-height: 52px;text-shadow: 0 1px 0 #fff;\"><span id=\"current_obj\" style=\"font-weight: normal;\"><span class=\"breadcrumb item-0\">My Affiliates<img alt=\"&gt;\" style=\"margin-right:5px\" src=\"../img/admin/separator_breadcrumb.png\"></span><span class=\"breadcrumb item-1\">Affiliates</span></span></h3></div></div>'); 
     $("#content").append("<iframe style=\"width: 100%;height: 100%;\" src=\"http://www.myaffiliates.gr/\"></iframe>"); 

    }); 
</script> 
관련 문제