繁体   English   中英

ipython javascript不更新文本

[英]ipython javascript not updating text

这似乎可以用作在浏览器中打开的普通html / javascript文件,但是当我将其放在IPython笔记本中时,仅按钮文本在更新(段落文本不更新)。 是什么原因造成的?

IPython笔记本单元代码:从IPython.display导入HTML,Javascript,显示

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 / javascript:

<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>

Kartikeya建议有效:

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM