div代码没有闭合怎么办?

如果div没有闭合,会找下一个</div>来闭合,页面会乱

如果没有任何一个</div>来闭合,就不会很乱,layout的时候会自动处理闭合的,一样不会提示错误

标记语言对格式要求不高,很多时候在不闭合的情况下也能正常运行

thinkphp html中input问题 提示input标签没有闭合 ,望大神指导,非常感谢,在线等待。。。

把报错的信息发出来。你发这段字段不一定有错,不要太相信多少多少行出错这种信息。错误是肯定的。但行数不一定对

HTML是否闭合以及自动修复

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Collections;usingSystem.Diagnostics;namespace查HTML是否闭合{classTagsList{privateArrayListdata;publicintSize{get{returndata.Count;}}publicTagsList(){data=newArrayList();}publicvoidadd(Stringstr){data.Add(str);}publicstringget(intindex){if(index<data.Count)return(string)data[index];elsereturnnull;}publicboolremove(stringstr){if(data.IndexOf(str)==-1)returnfalse;data.Remove(str);returntrue;}publicvoidremove(intindex){data.RemoveAt(index);}}publicclassTagsChecker{publicstaticboolcheck(stringstr){TagsList[]unclosedTags=getUnclosedTags(str);if(unclosedTags[0

].Size;i++){if(unclosedTags[1].

get(i)!=null)returnfalse;}returntrue;}publicstaticstringfix(Stringstr){StringBuilderfixeds=newStringBuilder();//存放修复后的字符串

TagsList[]unclosedTags=getUnclosedTags(str);//生成新字符串for(inti=unclosedTags[0

].Size-1;i-1;i–){fixeds.Append(“<“+unclosedTags[0].

get(i)+””);}fixeds.Append(str);for(inti=unclosedTags[1

].Size-1;i-1;i–){Strings=null;if((s=unclosedTags[1].

get(i))!=null){fixeds.Append(“</”+s+””);}}returnfixeds.ToString();}privatestaticTagsList[]getUnclosedTags(Stringstr){StringBuildertemp=newStringBuilder();//存放标签TagsList[]unclosedTags=newTagsList[2];unclosedTags[0]=newTagsList();//前不闭合,如有</div而前面没有<div

unclosedTags[1]=newTagsList();//后不闭合,如有<div而后面没有</divboolflag=false;//记录双引号”或单引号’charcurrentJump=”;//记录需要跳过”还是””charcurrent=”

,last=”;//当前上一个//开始判断for(inti=0;i<str.Length;){current=str[i++];//读取一个字符if(current=='”‘||current==’\”){flag=flag?false:true;//若为引号,flag翻转

currentJump=current;if(flag){while(i<str.Lengthstr[i++]!=currentJump);//跳过引号之间的部分flag=false;}}elseif(current=='<‘){//开始提取标签current=str[i++];if(current==’/’){//标签的闭合部分,如</divcurrent=str[i++];//读取标签while(i<str.Lengthcurrent!=”){temp.Append(current);current=str[i++];}//从tags_bottom移除一个闭合的标签if(!unclosedTags[1

].remove(temp.ToString())){//若移除失败,说明前面没有需要闭合的标签

unclosedTags[0

].add(temp.ToString());//此标签需要前闭合}temp.Remove(0

,temp.Length);//清空temp}else{//标签的前部分,如<divlast=current;while(i<str.Lengthcurrent!=”current!=”current!=”){temp.Append(current);last=current;current=str[i++];}//已经读取到标签,跳过其他内容,如<divid=test跳过id=testwhile(i<str.Lengthcurrent!=”){last=current;current=str[i++];if(current=='”‘||current==’\”){//判断双引号flag=flag?false:true;currentJump=current;if(flag){//若引号不闭合,跳过到下一个引号之间的内容while(i<str.Lengthstr[i++]!=currentJump);current=str[i++];flag=false;}}}if(last!=’/’current==”)//判断这种类型:<TagName/

unclosedTags[1

].add(temp.ToString());

temp.Remove(0

,temp.Length);}}}returnunclosedTags;}}classProgram{staticvoidMain(string[]args){Console.WriteLine(“–功能测试–“);//stringstr1=”tt</uss</aaa<divname=\”<test\”id=’3’other='<test'<bsff”;stringstr1=”<ptt<table<tr<tdkdkf</td</tr<tr<td323</td</p”;stringstr2=”tt<uss</u<divid=testname=\”<test\”<afds</a</div”;Console.WriteLine(“检查文本”+str1);Console.WriteLine(“结果:”+TagsChecker.check(str1));

Console.WriteLine(“检查文本”+str2);Console.WriteLine(“结果:”+TagsChecker.check(str2));

Console.WriteLine(“修复文本”+str1);Console.WriteLine(“结果:”+TagsChecker.fix(str1));for(inti=0;i<10;i++){str1+=str1;}Console.WriteLine();

Console.WriteLine(“–效率测试–“);Console.WriteLine(“文本长度:”+str1.Length);longt1=DateTime.Now.Ticks;boolclosed=TagsChecker.check(str1);longt2=DateTime.Now.Ticks;

Console.WriteLine(“检查用时:”+(t2-t1)+”毫秒结果:”+closed);Console.WriteLine(“修复用时:”+(t3-t2)+”毫秒”);}}}

怎样快速找到HTML网页中没闭合的标签呢

您好您可以安装微软的visual studio的web设计对象拥有异常强大年夜的html代码检测功能像标签没有闭合的和标签大年夜小写不一致等等都是可以检测出来的您可以下载来用

怎么检查一个网页的html标签都闭合了

如果用DW的话,可以这样:先选定一个要测试的<div> ,然后在编辑里面有一个“选择父标签”选项,点击后就会选定该div所有内容,这样这个div是否闭合就一目了然了

在js里我用 innerHtml或者.html() 获取的img标签不闭合

<img src=”/data/upload/help/202211/02/c0a7ae7d513f4beb2bc203d6f339f1b5.”  alt=”上海鲜花港 ” /> 本身就是单标签 . “/”表示闭合有没有无所谓的,

用JS获取到的 是(.html())

<img src=”/data/upload/help/202211/02/c0a7ae7d513f4beb2bc203d6f339f1b5.”  alt=”上海鲜花港 ” >

是没有“/”的。这个时候表示的是一个字符串类型是string,如果你想把这个结果赋值给另外的div或者什么也不影响。