0
我想使用Jquery突出顯示正常html表中特定列中的特定數據字段。可以爲此場景提供一段代碼。我已經實現的是突出顯示Solr的記錄,但不知道如何將其應用於連續的確切列。使用Jquery突出顯示錶中特定的數據列
var newresult = {"_header": {
"nvPairs": [
"status",
0,
"QTime",
3,
"params",
{
"nvPairs": [
"hl.fragsize",
"100000",
"hl.simple.pre",
"<em>",
"hl.fl",
"name",
"wt",
"javabin",
"hl.maxAnalyzedChars",
"100000",
"hl",
"true",
"version",
"2",
"hl.highlightMultiTerm",
"true",
"hl.snippets",
"100",
"hl.useFastVectorHighlighter",
"true",
"q",
"harsha",
"hl.regex.slop",
"0.5",
"hl.regex.pattern",
"[-\\w ,/\n\\\"']*",
"hl.simple.post",
"</em>"
]
}
]
},
"_results": [
{
"id": "21",
"name": [
"asd asda fsdfsdfds harsha sadaks asdasd sad fsddsf dsfdsf dsf sdf dsdsf sdfdsf dsfdsf dsf fdsdfsd fdsfdsf dfdsfdsfds dsfsdf d f ds fdf df df dsfdsf dfdsf d fdsdf dfs harsha"
],
"_version_": 1508203924863058000
}
],
"_highlightingInfo": {
"nvPairs": [
"21",
{
"nvPairs": [
"name",
[
"asd asda fsdfsdfds <em>harsha</em> sadaks asdasd sad fsddsf dsfdsf dsf sdf dsdsf sdfdsf dsfdsf dsf fdsdfsd fdsfdsf dfdsfdsfds dsfsdf d f ds fdf df df dsfdsf dfdsf d fdsdf dfs <em>harsha</em>"
]
]
}
]
},
"_highlighting": {
"21": {
"name": [
"asd asda fsdfsdfds <em>harsha</em> sadaks asdasd sad fsddsf dsfdsf dsf sdf dsdsf sdfdsf dsfdsf dsf fdsdfsd fdsfdsf dfdsfdsfds dsfsdf d f ds fdf df df dsfdsf dfdsf d fdsdf dfs <em>harsha</em>"
]
}
},
"elapsedTime": 19,
"response": {
"nvPairs": [
"responseHeader",
{
"nvPairs": [
"status",
0,
"QTime",
3,
"params",
{
"nvPairs": [
"hl.fragsize",
"100000",
"hl.simple.pre",
"<em>",
"hl.fl",
"name",
"wt",
"javabin",
"hl.maxAnalyzedChars",
"100000",
"hl",
"true",
"version",
"2",
"hl.highlightMultiTerm",
"true",
"hl.snippets",
"100",
"hl.useFastVectorHighlighter",
"true",
"q",
"harsha",
"hl.regex.slop",
"0.5",
"hl.regex.pattern",
"[-\\w ,/\n\\\"']*",
"hl.simple.post",
"</em>"
]
}
]
},
"response",
[
{
"id": "21",
"name": [
"asd asda fsdfsdfds harsha sadaks asdasd sad fsddsf dsfdsf dsf sdf dsdsf sdfdsf dsfdsf dsf fdsdfsd fdsfdsf dfdsfdsfds dsfsdf d f ds fdf df df dsfdsf dfdsf d fdsdf dfs harsha"
],
"_version_": 1508203924863058000
}
],
"highlighting",
{
"nvPairs": [
"21",
{
"nvPairs": [
"name",
[
"asd asda fsdfsdfds <em>harsha</em> sadaks asdasd sad fsddsf dsfdsf dsf sdf dsdsf sdfdsf dsfdsf dsf fdsdfsd fdsfdsf dfdsfdsfds dsfsdf d f ds fdf df df dsfdsf dfdsf d fdsdf dfs <em>harsha</em>"
]
]
}
]
}
]
}
};
var highlight = {};
$.each(newresult._highlighting, function(i, hitem){
var match = hitem.name[0].match(/<em>(.*?)<\/em>/);
// var match = hitem.description[0].match(/elegant/g);
console.log("match "+match);
highlight[i] = match[1];
});
var res1 = newresult._highlighting;
var results;
var result;
for(var res2 in res1)
{
var hlight = res1[res2].name;
results= highlight[res2];
}
$.each(hlight, function(ix, items){
var word = results;
result = items.replace(new RegExp(word, 'g'),word);
});
//var res = newresult.response.nvPairs[5].nvPairs[1].nvPairs[1];
//var word ="harsha";
//var result = res[0].replace(new RegExp(word, 'g'), '<em>harsha</em>');
$("body").append('<div>' + result + '</div>');
});
如果沒有示例HTML,問題太模糊「特定列中的特定數據字段」沒有描述您如何選擇該數據或列。請顯示你的嘗試。 –