清除文本区域会中断其他JS函数
Clearing textarea breaks other JS functions
我正在为一台将与用户对话的计算机建模。控制台能够在屏幕上打印消息并重新加载,几乎没有问题。然而,我目前有一个按钮被设置为"清除"计算机屏幕上的内容——一旦按下这个按钮,在重新加载页面之前,其他功能将无法工作。
到目前为止我的工作。通过按几次"pwr"或"send"来重新创建问题。按下后,两个按钮都会在屏幕上打印信息。如果你按下"清除",屏幕会按照我的意愿清除,但两个按钮都不会再在屏幕上打印消息。.val(")是否以某种方式使该字段不可编辑?
# app/assets/javascripts/app.computress.coffee
App.Computress =
clear: ->
$("#hm_disp_txt").val('')
greet: ->
App.Computress.prints("Welcome!")
prints: (str) ->
$("#hm_disp_txt").append(str + "'n")
$(document).on "click", "[data-behavior~=computress-listen]", =>
App.Computress.prints("ping received")
$(document).on "click", "[data-behavior~=computress-listen-clear]", =>
App.Computress.clear()
$(document).on "click", "[data-behavior~=computress-power]", =>
App.Computress.greet()
$(document).on "click", "[data-behavior~=computress-reload]", =>
location.reload()
# home.html/erb
<div id="computress">
<div id="home_console">
<textarea id="hm_disp_txt" readonly>Zzzzzz....</textarea>
</div>
<div id="home_input">
<div id="hm_inp_txt">></div>
<input type="text" id="user_inp" placeholder="...say "hello"?">
<%= link_to "send", "#", data: {behavior: "computress-listen"}, id: "talkbutton", class: "comptrss_mono_txt" %>
<%= link_to "C", "#", data: {behavior: "computress-listen-clear"}, id: "clearbutton", class: "comptrss_mono_txt" %>
<%= link_to "pwr", "#", data: {behavior: "computress-power"}, id: "pwrbutton", class: "comptrss_mono_txt" %>
<%= link_to "reload", "#", data: {behavior: "computress-reload"}, id: "rldbutton", class: "comptrss_mono_txt" %>
</div>
</div>
我相信这是因为您混淆了.append()
和.val()
。。。尝试使用:
$("#hm_disp_txt").val( $("#hm_disp_txt").val() + "'n" + str );
而不是:
$("#hm_disp_txt").append(str + "'n");
在您的prints()
方法中
相关文章:
- 为其他JS生成定义“;编译器”;来自TypeScript定义文件
- 节点:'最佳实践'使用其他js文件的js文件
- 地理定位在Jsfidle中工作,但不在任何其他JS编辑器中
- Ajax 请求正在取消页面上的其他 JS 事件
- Meteor-如何从其他JS文件中调用外部类方法
- EXT JS可以't从其他.js中获取Define
- jQuery.menu与其他JS冲突
- Pjax.页面上的其他JS脚本不会;不起作用
- 清除文本区域会中断其他JS函数
- AJAX没有加载其他js和css风格
- 如何将 jquery 和其他.js库与 Angular2 一起使用
- 使用 JS 代码设置鼠标位置,并将位置放在其他 JS 代码中
- 创建一个使用其他 js 库的可嵌入 JavaScript 小部件
- 从其他 JS 执行一个函数
- 迁移解析后无法引用其他 JS 代码
- 如何将 angularjs 变量值获取到其他.js文件
- 用ajax加载的html内容不会检测到其他js函数
- 有没有一种方法可以将json文件与所有其他js文件一起加载
- 当其他JS脚本包含在html页面中时,Ajax请求不起作用
- 有没有办法在不渲染任何其他 js 文件的情况下在 rails 控制器方法中发出警报/弹出窗口