这是输入在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代码有什么问题?错误显示[对象对象]。输出应该是UNCOMMENT输入数据并显示在&#34; txtArea&#34;
Codepen链接:http://codepen.io/anon/pen/BjVWwB
答案 0 :(得分:0)
这是固定功能:
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