Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

js div高亮提醒

有10个div,点击都有高亮提示,但是每次只能点两个,不是checkbox而是单纯的div包含内容,或者10段不同的文字,用js怎么实现呢?


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

1 Answer

0 votes
by (71.8m points)

大体思路

  • 给每个div添加一个checked属性默认为false,
    div[i].checked = false;

  • 点击的同时改变当前div的checked属性,div[i].checked = !div[i].checked

  • 点击div的同时,遍历所有div的checked属性,如果有两个为checked,则return false退出函数,否则对该div的checked属性进行取反赋值。又有一些具体的条件判断,自己按照思路慢慢踩就出来。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...