好的,我正在使用Skulpt在网页上编写Python。我想在解释器中的文本更改后,一个按钮被点击。但是,无论我如何尝试,文本区域中的代码都不会改变。但是,如果我“警告”文本区的值,它会调出更改后的版本,表明按钮可以工作。
我还发现了这个问题:Set value of textarea in jQuery,但这里没有任何东西对我的情况有帮助:(
下面是我尝试的方法:
<textarea id="theTextArea">print 'Hello World!'</textarea>
<div id="controls">
<button type="button" onclick="replaceCode()">Replace</button>
<button type="button" onclick="testAlert()">Alert Me</button>
</div>
<script>
function replaceCode(){
document.getElementById('theTextArea').value = "print 'Thats new code'";
};
function testAlert(){
alert(document.getElementById('theTextArea').value);
};
</script>此外,我还尝试更改了.innerHTML和.text,但实际上没有任何内容替换文本区中的文本。
如果有人认为它可以帮助我,我可以添加完整的HTML文档,以及在线python解释器的整个Skulpt设置,以防它不允许我以常规的方式更改textarea的值。但是,如果现在不需要代码,我不希望现在有一堵墙的代码。
发布于 2018-01-13 20:59:41
您忘记了onclick%s中的方括号。您应该使用HTMLTextAreaElement.innerHTML来更改文本区域的内容
function replaceCode(){
document.getElementById('theTextArea').innerHTML = "print 'Thats new code'";
};
function testAlert(){
alert(document.getElementById('theTextArea').innerHTML);
};<textarea id="theTextArea">print 'Hello World!'</textarea>
<div id="controls">
<button type="button" onclick="replaceCode()">Replace</button>
<button type="button" onclick="testAlert()">Alert Me</button>
</div>
发布于 2018-01-15 04:46:09
原来Skulpt在我修改python代码的时候只需点击一下按钮就行了。我需要使用一个函数,该函数可能是在Skulpt附带的某个导入文档中定义的。该函数如下所示:
editor.setValue("print 'Thats new code'");然后它实际上在文本区域中发生了变化:)
https://stackoverflow.com/questions/48240054
复制相似问题