Javascript点击功能不起作用.在输出中显示错误 [对象对象]

Javascript onclick function not working . Showing error [object object] in output

本文关键字:对象 显示 错误 输出 功能 不起作用 Javascript      更新时间:2023-09-26

这是要在txtBox中输入的输入:

<!-- <#assign SEMFirmNameAlt = " - ${site.data.SEMFirmNameAlt}">
    <#if site.data.SEMFirmNameAlt = "">
        <#assign SEMFirmNameAlt = "">
    </#if> -->  

这是整个代码:

<textarea type="text" id="txtBox" ></textarea>
<br /><br />
<input type="button" value="Process String" onclick="processString()" style="width:250px" />
<br /><br />
<textarea id="txtArea" rows="8" cols="30"></textarea>
<script>
    function processString() {
          document.getElementById("txtArea").value = "";
          var comments = $("txtBox").contents().filter(function() {
            return this.nodeName === "#comment"
          });
          var result = $(comments[0]).replaceWith(function(){
            return document.createTextNode(this.data);
          });
          if (result != null){
            document.getElementById("txtArea").value = result;
          }
    }     
</script>

这个JavaScript代码有什么问题?显示 [对象对象] 时出错。输出应取消注释输入数据并显示在"txtArea"中。

代码笔链接:http://codepen.io/anon/pen/BjVWwB

这是固定函数:

function processString() {
  var txtArea = document.getElementById("txtArea"); 
  txtArea.value = "";
  var comments = $($('#txtBox').val());
  var valueStripped = '';  
  comments.filter(function () {
    return this.nodeName == "#comment";
  }).each(function (index, value) {
    valueStripped += value.data;
  });
  if (valueStripped != ''){
    txtArea.value = valueStripped;
  }
}     

这是固定的Codepen链接:http://codepen.io/anon/pen/vLrxvw