2014-09-14 4 views
1

이것은 일반 html/javascript 파일이 브라우저에서 열린 것처럼 보이지만 IPython 전자 필기장에 넣을 때 버튼 텍스트 만 업데이트됩니다 (단락 텍스트는 업데이트되지 않습니다). 무엇이 이것을 일으킬 수 있습니까?ipython javascript가 텍스트를 업데이트하지 않습니다.

IPython 노트북 휴대 코드 :

<html> 
<body> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> 
<p id="demo">A Paragraph.</p> 
<button id="something">Try it</button> 
<script> 
$("#something").click(function() { 
$('#demo').text("Changed text"); 
$('#something').text('Change button'); 
}); 
</script> 
</body> 
</html> 
+0

랩 IPython.display 가져 오기 HTML, 자바 스크립트, 디스플레이

display(HTML(""" <p id="demo">A Paragraph.</p> <button id="something">Try it</button> """)) js = """ $("#something").click(function() { $('#demo').text("Changed text"); $('#something').text('Change button'); }); """ js = Javascript(js) display(js) 

일반 HTML/자바 스크립트에서 document.ready() 안의 jquery 코드. –

+0

@ 카르티 케아는 필요하지 않아야합니다. 코드는 DOM 요소가 영향을 미칩니다. (어쩌면 ipython 이상한가요?) – Pointy

+1

또한 jQuery 1.3 아주 오래된 것입니다. – Pointy

답변

1

무루 간의 제안 일 :

from IPython.display import HTML, Javascript, display 

display(HTML(""" 
<p id="demo">A Paragraph.</p> 
<button id="something">Try it</button> 
""")) 
js = """ 
$(document).ready(
function() { 
    $("#something").click(function() { 
     $('#demo').text("Changed text"); 
     $('#something').text('Change button'); 
     }); 
    }); 
""" 
js = Javascript(js) 
display(js) 
관련 문제