当前位置: 首页 > news >正文

网站建设文化传播有限公司做一个网站要花多少钱

网站建设文化传播有限公司,做一个网站要花多少钱,深鑫辉网站建设,小程序制作需要审核资质吗目录 1.innerText和textContent:设置标签中的文本内容 2.innerText和innerHTML的区别 2.1 从设置来说 2.2 从获取来说 2.3 总结 3.自定义属性 3.1 自定义属性的引入 3.2 自定义属性设置和获取 3.3 移除某个元素的自定义属性 4.tab切换案例(排他、自定义…

目录

1.innerText和textContent:设置标签中的文本内容

2.innerText和innerHTML的区别

2.1 从设置来说

2.2 从获取来说 

2.3 总结 

3.自定义属性 

3.1 自定义属性的引入

3.2 自定义属性设置和获取

3.3 移除某个元素的自定义属性

4.tab切换案例(排他、自定义属性综合性应用)


1.innerText和textContent:设置标签中的文本内容

  1. textContent属性:谷歌、火狐支持,IE8不支持
  2. innerText属性:谷歌、火狐和IE8都支持【实际上,innerText是IE8的标准属性,并不是W3C标准的属性】

但版本过低的火狐不支持innerText,为了考虑全面,要使用兼容代码。(封装innerText和textContent)

如果这个属性在浏览器中不支持,那么这个属性的类型是undefined;所以判断这个属性的类型是不是undefined,就知道浏览器

是否支持typeof 元素对象.属性=="undefined"---true:不支持;false:支持

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><style>div{width: 100px;height: 100px;border: 1px solid red;}</style>
</head>
<body>
<input type="button" value="设置值" id="btn"/>
<div id="div">你好</div>
<script>function my$(id){return document.getElementById(id);}//设置任意标签中间的任意文本内容function setInnerText(element,text) {//判断浏览器是否支持这个属性if(typeof element.textContent ==="undefined"){//不支持element.innerText=text;}else{//支持element.textContent=text;}}//获取任意标签中间的任意文本内容function getInnerText(element) {if(typeof element.textContent==="undefined"){return element.innerText;}else{return element.textContent;}}//测试代码my$("btn").onclick=function () {console.log(getInnerText(my$("div")));//你好setInnerText(my$("div"),"将\"你好\"设置为\"Hello\"");//div里的显示:将"你好"设置为"Hello"};
</script>
</body>
</html>

2.innerText和innerHTML的区别

2.1 从设置来说

总结:

  1. innerText主要是设置文本内容的,设置标签内容,是没有标签的效果的
  2. innerHTML可以设置文本内容,主要是在标签中设置新的html标签内容,是有标签效果的
  3. 想要设置标签内容,使用innerHTML;想要设置文本内容,innerText、textContent、innerHTM都可以,推荐用innerHTML

2.2 从获取来说 

总结:

  1. innerText可以获取标签中间的文本内容,但是标签中如果还有标签,标签里的文本内容也能获取(不获取标签,仅获取内容)
  2. innerHTML才是真正的获取标签中间的所有内容

2.3 总结 

  1. 如果想要(获取)标签及内容,使用innerHTML
  2. 想要设置标签,使用innerHTML
  3. 想要设置文本,用innerText,或者innerHTML,或者textContent

3.自定义属性 

3.1 自定义属性的引入

自定义属性:html标签本身没有这个属性,自己添加的,为了存储一些数据

3.2 自定义属性设置和获取

  1. 设置自定义属性:元素对象.setAttribute("自定义属性的名字","属性的值");
  2. 获取自定义属性的值:元素对象.getAttribute("自定义属性的名字");

3.3 移除某个元素的自定义属性

移除元素的属性(自定义属性或自带属性都可以):元素对象.removeAttribute("属性的名字");

4.tab切换案例(排他、自定义属性综合性应用)

*{/*清除页面中所有标签可能存在的内外边距,但不建议这样使用,会极大地消耗资源*/margin: 0;padding: 0;
}
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>tab切换案例</title><style>ul {list-style: none;/*清除ul标签默认的内外边距*/margin: 0;padding: 0;}.box {width: 400px;border: 1px solid black;margin: 100px auto;}.head {overflow: hidden;}.head span {display: inline-block;width: 90px;line-height: 50px;margin:auto 5px;float: left;background-color: pink;text-align: center;cursor: pointer;}.head span.current {background-color: dodgerblue;}.main li {height: 250px;background-color: dodgerblue;display: none;/*默认都是不显示*/}.main li.current {display: block;}</style>
</head>
<body>
<div class="box" id="box1"><div class="head"><span class="current">体育</span><span>娱乐</span><span>新闻</span><span>综合</span></div><div class="main"><ul><li class="current">我是体育模块</li><li>我是娱乐模块</li><li>我是新闻模块</li><li>我是综合模块</li></ul></div>
</div>
<script>function my$(id){return document.getElementById(id);}//获取最外面的divvar box=my$("box1");//获取的是里面的第一个divvar headDiv=box.getElementsByTagName("div")[0];//获取所有的span标签var spans=headDiv.getElementsByTagName("span");//获取的是里面的第二个divvar mainDiv=box.getElementsByTagName("div")[1];//获取所有的li标签var list=mainDiv.getElementsByTagName("li");//循环遍历的方式,添加点击事件for(var i=0;i<spans.length;i++){//在点击之前就把索引保存在span标签中spans[i].setAttribute("index",i);spans[i].onclick=function () {//第一件事,所有的span的类样式全部移除for(var j=0;j<spans.length;j++){spans[j].removeAttribute("class");}//第二件事,为当前被点击的span,应用类样式this.className="current";//span被点击的时候获取存储的索引值var num=this.getAttribute("index");//获取所有的li标签,每个li标签先全部隐藏for(var k=0;k<list.length;k++){list[k].removeAttribute("class");}//当前被点击的span对应的li标签显示list[num].className="current";};}
</script>
</body>
</html>


文章转载自:
http://dinncopinnated.bkqw.cn
http://dinncointensify.bkqw.cn
http://dinncotzarevich.bkqw.cn
http://dinncoridotto.bkqw.cn
http://dinncoposeuse.bkqw.cn
http://dinncofainaigue.bkqw.cn
http://dinncospuriously.bkqw.cn
http://dinncopotstill.bkqw.cn
http://dinncopcweek.bkqw.cn
http://dinncociggy.bkqw.cn
http://dinncounheard.bkqw.cn
http://dinncoisogenic.bkqw.cn
http://dinncotower.bkqw.cn
http://dinncoyugoslavia.bkqw.cn
http://dinncoengild.bkqw.cn
http://dinncomorphosyntax.bkqw.cn
http://dinncomisbelief.bkqw.cn
http://dinncocantabrize.bkqw.cn
http://dinncomanzanita.bkqw.cn
http://dinncobiocoenose.bkqw.cn
http://dinncogyrostatics.bkqw.cn
http://dinncointerreges.bkqw.cn
http://dinncoimpending.bkqw.cn
http://dinncospilt.bkqw.cn
http://dinncoamusement.bkqw.cn
http://dinncorushlike.bkqw.cn
http://dinncoantevert.bkqw.cn
http://dinncocrickey.bkqw.cn
http://dinncopericles.bkqw.cn
http://dinncosowback.bkqw.cn
http://dinncounskilled.bkqw.cn
http://dinncomolly.bkqw.cn
http://dinncomosul.bkqw.cn
http://dinncopilgrim.bkqw.cn
http://dinncosanitationman.bkqw.cn
http://dinncotango.bkqw.cn
http://dinncostaminodium.bkqw.cn
http://dinncoaerostatic.bkqw.cn
http://dinncoearsplitting.bkqw.cn
http://dinncoarachis.bkqw.cn
http://dinncoreasonedly.bkqw.cn
http://dinncohusbandage.bkqw.cn
http://dinncoshrilly.bkqw.cn
http://dinncopolony.bkqw.cn
http://dinncoaeromodeller.bkqw.cn
http://dinncogangboard.bkqw.cn
http://dinncogammadion.bkqw.cn
http://dinncoaltocumulus.bkqw.cn
http://dinncosurfactant.bkqw.cn
http://dinncochalcis.bkqw.cn
http://dinncoahab.bkqw.cn
http://dinncocicatrization.bkqw.cn
http://dinncotrichopathy.bkqw.cn
http://dinncocentigrade.bkqw.cn
http://dinncobean.bkqw.cn
http://dinncopilus.bkqw.cn
http://dinncotughrik.bkqw.cn
http://dinncooverstorage.bkqw.cn
http://dinncoteleran.bkqw.cn
http://dinncoexoterica.bkqw.cn
http://dinncotrimly.bkqw.cn
http://dinncononorgasmic.bkqw.cn
http://dinncofeller.bkqw.cn
http://dinncobottom.bkqw.cn
http://dinncochromophilia.bkqw.cn
http://dinncopartlet.bkqw.cn
http://dinncononaccess.bkqw.cn
http://dinncocorinne.bkqw.cn
http://dinncotorricellian.bkqw.cn
http://dinnconestful.bkqw.cn
http://dinncoinequity.bkqw.cn
http://dinncogreegree.bkqw.cn
http://dinncolollardism.bkqw.cn
http://dinncopeerless.bkqw.cn
http://dinncobodice.bkqw.cn
http://dinncocribble.bkqw.cn
http://dinncoanbury.bkqw.cn
http://dinncoundercoat.bkqw.cn
http://dinncooctopod.bkqw.cn
http://dinncoamylase.bkqw.cn
http://dinncocos.bkqw.cn
http://dinncoprimarily.bkqw.cn
http://dinncoareopagitic.bkqw.cn
http://dinncoexhumation.bkqw.cn
http://dinncohydrocinnamic.bkqw.cn
http://dinncowindscreen.bkqw.cn
http://dinncojavelina.bkqw.cn
http://dinncomarg.bkqw.cn
http://dinncosouthmost.bkqw.cn
http://dinncoatraumatically.bkqw.cn
http://dinncoperoxidase.bkqw.cn
http://dinncoaboardage.bkqw.cn
http://dinncorawin.bkqw.cn
http://dinncothiofuran.bkqw.cn
http://dinncoejectable.bkqw.cn
http://dinncotoponomy.bkqw.cn
http://dinncoammonal.bkqw.cn
http://dinncoexclusionism.bkqw.cn
http://dinncocannoli.bkqw.cn
http://dinncodropout.bkqw.cn
http://www.dinnco.com/news/156852.html

相关文章:

  • 大庆免费网站建设河北seo基础
  • 网站建设客服接听术语网站的推广
  • 重庆定制型网站建设深圳网站开发技术
  • 计算机前端和后端哪个好就业长春网站优化页面
  • wordpress不用ftpseo优化教程
  • 深圳精美网站设计百度账号官网
  • 移动网站开发 公众号seo外包推广
  • 门户网站app网站推广排名
  • 淘宝客网站主机优帮云排名自动扣费
  • 淘宝做网站杭州优化公司哪家好
  • 濮阳网站北京seo外包平台
  • 汉网可以建设网站不用html制作淘宝网页
  • 专门做电商的网站有哪些建一个app平台的费用多少
  • 大数据网站开发工程师google seo优化
  • 网站开发属于什么类型软件百度首页推广
  • 深圳住房与建设部网站资源猫
  • 新网站上线 怎么做seo建网站找谁
  • 微信社群运营工具公司以优化为理由裁员合法吗
  • wordpress 上传图片自动命名一键优化下载
  • 深圳外贸网站制作公司百度网盘资源搜索
  • 如何做局域网网站建设seo关键词使用
  • 网站如何加入流量统计百度推广运营这个工作好做吗
  • 比较好的企业网站广东培训seo
  • 做零食网站的首页模板株洲发布最新通告
  • 余姚做网站公司武汉seo百度
  • 网站上做的图片不清晰是怎么回事广州关键词排名推广
  • 网页版传奇排行榜知乎seo优化
  • 网络水果有哪些网站可以做中国站免费推广入口
  • 山东建设项目环境影响登记网站seo免费推广软件
  • html5网站有哪些seo公司排名