我正在使用以下代码来处理一些字符串,当它到达innerHTML部分时,我想将tittxt0变量字符串数据着色为蓝色。我知道如果我得到一个dom元素怎么做但我不知道如何只为tittxt0变量数据着色并离开 限制chars0独自。谢谢你的时间。
var tittxt0 = txt0[i].split("++++")[0];
var txt00 = txt0[i].split("++++")[1];
var limitchars0 = txt00.substring(0,100);
var limitchars1 = txt00.substring(100, txt00.length);
var codecou0=limitchars1.split("[code]");
if(codecou0.length>1){paras0[i].innerHTML ="[code]" }
if(limitchars0.length ==80){
paras0[i].innerHTML += tittxt0+"<br>"+limitchars0+ " ...";
tittxt0.style.color="blue";
}else{
paras0[i].innerHTML += tittxt0+"<br>"+limitchars0;
tittxt0.style.color="blue";
}
答案 0 :(得分:0)
我通过在段落中创建一个变量并在强元素中插入另一个变量来解决这个问题,这是完全需要它的人的函数。
callrecb0:function(rectxt){
var forumcon0 = document.getElementsByClassName("forumcon0");
var txt0 = rectxt.split(":::");
for(var i=0; i<txt0.length; i++){
var newpara0=document.createElement("p");
forumcon0[0].appendChild(newpara0);
var paras0=forumcon0[0].getElementsByTagName("p");
paras0[i].setAttribute("id", "x"+i);
custevents.addevent(paras0[i], 'click',custevents.forlink0);
var tittxt0 = txt0[i].split("++++")[0];
var txt00 = txt0[i].split("++++")[1];
var limitchars0 = txt00.substring(0,35);
if(limitchars0.length==35){
var limitchars00 = txt00.substring(36,71);
}else{
limitchars00="";
}
var limitchars1 = txt00.substring(71, txt00.length);
//var limitTotatl0 = limitchars0.length+limitchars00.length;
//alert(limitTotal0);
//paras0[i].innerHTML += tittxt0+"<br>"
paras0[i].style.color="Blue";
var codecou0=limitchars1.split("[code]");
if(codecou0.length>1){paras0[i].innerHTML ="[code]" }
if(limitchars00.length >34){
paras0[i].innerHTML += tittxt0+"<br>"
paras0[i].style.color="Blue";
var newpara1=document.createElement("strong");
paras0[i].appendChild(newpara1);
newpara1.style.color="black";
newpara1.innerHTML+=limitchars0+"<br>"+limitchars00+" ...";
}else{
paras0[i].innerHTML += tittxt0+"<br>"
paras0[i].style.color="Blue";
var newpara1=document.createElement("strong");
paras0[i].appendChild(newpara1);
newpara1.innerHTML+=limitchars0+"<br>"+limitchars00;
newpara1.style.color="black";
}
if(i==txt0.length-2){
formstyle.odd();
}
}
},