Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

原生JS获取并让多个ul列表下的第一个li里的字符串,变成首位正常,中间****号

假设现在有3个ul,第一个li都是一长串的字符串,怎么让这3个的第一个Li的字符串变成首位正常,中间*号,用JS操作!

<ul id="one>
<li>尖山的是</li>
<li>1561</li>
</ul>
<ul id="two>
<li>尖232fd是</li>
<li>2561</li>
</ul>
<ul id="tr>
<li>wer2fsdf</li>
<li>8522</li>
</ul>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

image.png
假如是这样的东西,通过选择器获取第一个li
image.png
然后就是变成*,直接正则,或者其他方式一搞就OK
image.png
我直接拼接一下
image.png

Array.from(temp1.querySelectorAll('li:first-child')).forEach(v=>{
    v.innerText= (v.innerText,v.innerText[0]+('*'.repeat(v.innerText.length -1)))
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...