求助js代码,点击英文句子显示中文翻译,再次点击隐藏中文句子。

我想做个html电子书,默认是只显示英文原文,阅读的时候任意点击一句英文,在该句后面显示对应的中文翻译,再次点击英文句子又可以将中文翻译句隐藏。

显示效果像这样:
The heaven being spread with this pallid screen and the earth with the darkest vegetation, their meeting-line at the horizon was clearly marked. 蒙住苍穹的是这片灰白的帐幕,遍布大地的是这片黑苍苍的石南植物,它们在天际处交接,呈现出一条清晰分明的界线。In such contrast the heath wore the appearance of an instalment of night which had taken up its place before its astronomical hour was come: darkness had to a great extent arrived hereon, while day stood distinct in the sky. Looking upwards, a furze-cutter would have been inclined to continue work; looking down, he would have decided to finish his faggot and go home. The distant rims of the world and of the firmament seemed to be a division in time no less than a division in matter.

请大神赐一段js代码帮我实现这个效果。先谢过了!!

测试内容供参考(英文原文和中文翻译分别用<span>包裹,但位于一个<p>标签内):
​The heaven being spread with this pallid screen and the earth with the darkest vegetation, their meeting-line at the horizon was clearly marked. 蒙住苍穹的是这片灰白的帐幕,遍布大地的是这片黑苍苍的石南植物,它们在天际处交接,呈现出一条清晰分明的界线。In such contrast the heath wore the appearance of an instalment of night which had taken up its place before its astronomical hour was come: darkness had to a great extent arrived hereon, while day stood distinct in the sky. 在如此鲜明的对比下,这片荒原不等夜晚按天时自然降临,便早早蒙上了一层夜色;也就是说,在大地已经显出一片黑苍苍之际,天空依然清晰可见,昼光未逝。Looking upwards, a furze-cutter would have been inclined to continue work; looking down, he would have decided to finish his faggot and go home. 抬头望天,一位砍荆条的人会想要继续手头的活儿,然而低头凝望,他便会决定捆好柴束,打道回府。

用javascript写的,望采纳

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>
<span class="en">The heaven being spread with this pallid screen and the earth with the darkest vegetation, their meeting-line at the horizon was clearly marked. </span>
<span class="cn" style="display: none;">蒙住苍穹的是这片灰白的帐幕,遍布大地的是这片黑苍苍的石南植物,它们在天际处交接,呈现出一条清晰分明的界线。</span>
<span class="en">In such contrast the heath wore the appearance of an instalment of night which had taken up its place before its astronomical hour was come: darkness had to a great extent arrived hereon, while day stood distinct in the sky. </span>
<span class="cn" style="display: none;">在如此鲜明的对比下,这片荒原不等夜晚按天时自然降临,便早早蒙上了一层夜色;也就是说,在大地已经显出一片黑苍苍之际,天空依然清晰可见,昼光未逝。</span>
<span class="en">Looking upwards, a furze-cutter would have been inclined to continue work; looking down, he would have decided to finish his faggot and go home. </span>
<span class="cn" style="display: none;">抬头望天,一位砍荆条的人会想要继续手头的活儿,然而低头凝望,他便会决定捆好柴束,打道回府。
</p>
</body>
<script>
var enarr = document.getElementsByClassName("en");
for(var i=0;i<enarr.length;i++){
enarr[i].onclick = function(obj){
return function(){
if(obj.nextElementSibling.style.display=='none'){
obj.nextElementSibling.style.display='';
} else {
obj.nextElementSibling.style.display='none';
}
}
}(enarr[i]);
}
</script>

</html>
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

大家正在搜

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网