简体   繁体   English

如何从流星中的可编辑div中选择值而不是使用textarea.value?

[英]How do I select value from editable div in meteor instead of using textarea.value?

I used textarea tag instead this div[contentEditable="true] before, but it have an issue with text resizing on user typing; and this is the code, that worked in textarea version: 我之前使用textarea标签代替了这个div [contentEditable =“ true],但是在用户输入时调整文本大小存在问题;这是在textarea版本中有效的代码:

Template.mainFrame.events({
  'click button': function(e, t) {
    var inputted = t.find('#textarea').value;
    Session.set('input', inputted);
    t.find('#textarea').value = '';
  }
});

Template.mainFrame.someValue = function(){
    return Session.get('input');
};

html: HTML:

  <section>
        <div class="input">
          <div contentEditable="true" placeholder="type here" id="textarea">
            Lorem ipsum sit dolor
          </div>
          <button>
            click me
          </button>
        </div>
        <div class="output">
          {{#markdown}}
    {{someValue}}
          {{/markdown}}
        </div>
      </section>

But now it is not working; 但是现在它不起作用了。 I guess .value method only could be applicable to textarea or inputs and this kind of stuff; 我猜.value方法仅适用于textarea或输入以及此类内容;

So, the question is: which method in meteor do I use to select content inside div? 因此,问题是:我应该使用流星中的哪个方法来选择div中的内容?

This is not a meteor question, but really just about javascript (or jQuery to be precise). 这不是一个流星问题,但实际上只是关于javascript(确切地说是jQuery)。

The answer from here is that you can use: 这里得到的答案是您可以使用:

var inputted = t.find('#textarea').html();

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

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