11548 sujets

JavaScript, DOM et API Web HTML5

J'ai lu l'article de raphael pour afficher/masque des calques sans javascript, mais ça ne me convient pas (je veux que ça se passe à l'evenement clic, et que ça reste apres)
j'ai fais ça en javascript :

<script language="javascript">
function show(matiere) {
	if(document.getElementById(matiere).style.display=='none')
		document.getElementById(matiere).style.display='block';
	else
		document.getElementById(matiere).style.display='none';
}
function show(theme) {
	if(document.getElementById(theme).style.display=='none')
		document.getElementById(theme).style.display='block';
	else
		document.getElementById(theme).style.display='none';
}
</script>
</head>

<body>

<a href="#" onclick="show('matiere');">un boutton ou ce que tu veus( avec evenement onclick )</a>
<br  /><a href="#" onclick="show('theme');">un boutton ou ce que tu veus( avec evenement onclick )</a>
<span id="matiere" style="display:none;">matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere
matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere
matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere matiere </span>
<span id="theme" style="display:none;">theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme
theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme
theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme theme </span>


mais comment faire pour afficher les textes si javascript est desactivé ? Merci d'avance !
Modifié par Toutankharton (19 May 2005 - 22:45)
Au lieu de faire tes display: none dans le HTML fais-les en javascript sur un onload. Quelque chose comme :


function hideAll () {
   document.getElementById('matiere').style.display = 'none';
   document.getElementById('theme').style.display = 'none';
}

window.onload = hideAll;