I'm using the code below to dynamically add a highlight class to my span tags that are children of my "my_related_kw" div.
I'm currently adding a hard coded comma after each span tag, so that when the keywords are copied and pasted into the "Tags" input field, they are separated with commas.
However, I don't really want the comma's to show up on screen. Can I use jQuery to add the commas only when the content is pasted or when the copy or drag event is triggered?开发者_如何学Go
var html = jQuery('#content').html().toLowerCase();
jQuery(".my_related_kw").find("span").filter(function() {
return html.indexOf(jQuery(this).html()) != -1;
}).each(function() {
jQuery(this).addClass('highlight');
});
},
Use a hidden field containing your keywords with commas. Your input field could reflect the hidden field, just format it for display by removing commas.
If you need the commas to be there so that the user can copy/paste the text, then put the commas inside spans with a css style that makes them fully transparent. then they will be there and get copied but will not be visible.
精彩评论