من کدی نوشتم که کلمات کلیدی زبان برنامه نویسی رو در داکیومنت سرچ میکنه حالا باید کاری کنم که اون رو بصورت italic در بیاره مشکلم کار با استایلینگه
لطفا راهنمایی کنید.
0
اول یه prototype برای replace کردن همه کلمات مینویسیم و بعد از اون در تابع مون استفاده میکنیم به این شکل:
String.prototype.replaceAll=function(s1, s2) {return this.split(s1).join(s2)}
function MakeItalic(word,container) {
var str=document.getElementById(container).innerHTML;
var n=str.replaceAll(word,"<span style='font-style:italic'>"+word+"</span>");
document.getElementById(container).innerHTML=n;
}
<button onClick="MakeItalic('hello','dv')"> MAKE ITALC</button>
<div id="dv">hello worldhellohello hello hello </div>
سوال برنامه نویسی دارید؟
ندونستن عیب نیست، نپرسیدن چرا!