【问题标题】:Set HTML input value using Kinetic.js使用 Kinetic.js 设置 HTML 输入值
【发布时间】:2014-02-03 19:30:02
【问题描述】:

我想在用户点击时设置一个 HTML 输入框的值,使用 Kinetic.js。

这是输入框:

<input type="text" id="text_box">

这就是方法

stage.on('mousedown touchstart', function(evt) {
var shape = evt.targetNode;
if (shape) {
  if (shape.getFill() == 'green') { 
    // this is where the text box value should be changed.
    // I tried this:
    $("#text_box").val("hello");
  }     
}
  });

它似乎不起作用。

我该怎么做?

【问题讨论】:

  • 尝试提醒。

标签: javascript jquery html kineticjs


【解决方案1】:

您可能希望将侦听器绑定到形状本身而不是舞台上。

例如:

var layer = new Kinetic.Layer();
var shape = new Kinetic.Circle({ /*... */ });

shape.on('mousedown touchstart', function(e){
  var that = e.targetNode;
  // ..
});

layer.add(shape);

查看this example

【讨论】:

    【解决方案2】:

    这应该针对 DOM 中的文本框。

    document.getElementById("text_box").setAttribute("value","hello");
    

    document.getElementById("text_box").value = "hello";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-16
      • 2012-08-14
      • 1970-01-01
      • 2015-06-27
      • 2019-11-21
      • 1970-01-01
      • 2014-01-29
      • 2011-02-19
      相关资源
      最近更新 更多