有人可以帮我解决这个问题。我正在使用jquery的功能,允许您内在地编辑对象。以下代码将打印出当前的问题。
当您在文本周围添加标签以突出显示标签时,我会添加一条快速评论,上面写着“//标签添加到此处”
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></script>
<!--
* OPTIONS FOR: /js/browserdetection.js
* BROWSER NAME: BrowserDetect.browser
* BROWSER VERSION: BrowserDetect.version
* OS NAME: BrowserDetect.OS
-->
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
<script>
$(function () {
var array = [];
var count = 0;
step_through_array($.parseHTML('<div>test1<strong><img src="">test2 test32</strong>test3<p>test4</p></div><p><ins>test5</ins></p>'));
var obj = $.parseHTML('<div>test1<strong>test2 test31</strong>test3<p>test4</p></div><p><ins>test5</ins></p>');
step_through(obj);
$('#content').html(obj);
function step_through(obj) {
$.each(obj, function () {
if (this.childNodes.length != 0) {
step_through(this.childNodes);
} else if (this.nodeName == '#text') {
var data_set = '';
$.each(this.data.split(' '), function (name, value) {
if (array[count] == value) {
data_set += value + ' ';
} else {
data_set += '<ins>' + value + '</ins> ';//tags added here
}
count++;
});
this.data = data_set;
}
});
}
function step_through_array(obj) {
$.each(obj, function () {
if (this.childNodes.length != 0) {
step_through_array(this.childNodes);
} else if (this.nodeName == '#text') {
$.each(this.data.split(' '), function (name, value) {
array.push(value);
});
}
});
}
});
</script>
</head>
<body>
<div id="content"></div>
</body>
</html>