【问题标题】:object HTMLTextAreaElement javascript response对象 HTMLTextAreaElement javascript 响应
【发布时间】:2014-02-02 04:15:57
【问题描述】:

为什么我无法通过 Javascript/Jquery 获取 tinymce 文本区域中的内容?对于我尝试过的所有事情,它总是给我[object HTMLTextAreaElement]作为回应。我做错了什么?

Javascript:

function changeText2(){
  var content =  tinyMCE.getContent('content');
}

alert(content);

HTML:

<textarea id="content" onkeyup='changeText2()' name="page" cols="50" rows="15">
    tinymce editable content in here
</textarea>

【问题讨论】:

    标签: javascript jquery html tinymce textarea


    【解决方案1】:

    您正在获取 textarea 元素本身。要获取它的值,请添加.value

    【讨论】:

    • 现在你能告诉我为什么当我在文本区域输入时变量内容会发生变化吗?
    【解决方案2】:

    获取活动元素:

    var focused = document.activeElement;
    focused = WhoFocusseth(focused);
    
    function WhoFocusseth(focused){
    
        if(!focused || focused == document.body){
    
            focused = null;
    
            return focused;
    
        } else if(document.querySelector){
    
            focused = document.querySelector(":focus");
    
            return focused;
    
        }
    
    }
    

    现在你可以获取元素 id 了:

    var Which_Elem_In_Focus = focused.id;
    

    纯 Javascript。

    【讨论】:

      【解决方案3】:

      你只需要添加 .value

      alert(content.value);

      【讨论】:

      • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 1970-01-01
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 2018-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多