1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| <!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Réinjection du innerHTML</title>
<meta name="Author" content="NoSmoking">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
html, body {
font: 1em/1.25 Verdana;
}
h1, h2, h3 {
color: #069;
}
header, section {
margin: auto;
max-width: 60em;
}
.ligne-flex {
display: flex;
align-items: stretch;
height: 2em;
padding: .25em;
border: 1px solid #CCC;
border-radius: 2px;
line-height: 2em;
}
.ligne-flex > * + * {
margin-left: 1em;
}
.search {
background: #CDE;
}
select, input, button {
min-width: 6em;
font: inherit;
line-height: 100%;
}
</style>
</head>
<body>
<header>
<h1>Réinjection du innerHTML</h1>
<p>Simulation de la recherche :</p>
<p class="ligne-flex">
<button onclick = "fctSearch()">Highlight</button>
<button onclick = "fctClear()">Clear</button>
</p>
</header>
<section>
<h1>Titulus</h1>
<p>
Lorem <span>ipsum</span> dolor sit amet, consectetur adipiscing elit.
Pellentesque facilisis varius turpis, vitae porta justo pellentesque a.
Aliquam semper pellentesque ligula. Etiam et <span>ipsum</span> nisl.
Quisque venenatis gravida ex vel malesuada.
Phasellus pellentesque <span>lectus</span> tristique, dapibus leo ac, sodales magna.
Fusce dui risus, eleifend vitae turpis ac, congue scelerisque arcu.
Curabitur ornare risus id diam condimentum, vel accumsan neque accumsan.
Duis tortor ligula, rhoncus at ligula cursus, accumsan maximus tortor.
Praesent vitae suscipit lacus. Suspendisse quis metus <span>lectus</span>.
Mauris et est at purus tincidunt blandit.
</p>
<p class="ligne-flex">
<select onchange="majInput(this);">
<option value="">Choix</option>
<option value="Lunae dies">Lundi</option>
<option value="Martis dies">Mardi</option>
<option value="Mercurii dies">Mercredi</option>
<option value="Jovis dies">Jeudi</option>
<option value="Veneris dies">Vendredi</option>
<option value="Saturni dies">Samedi</option>
<option value="dies Dominicus">Dimanche</option>
</select>
<label>latin :</label>
<input type="text">
</p>
</section>
<script>
var htmlBefore = '';
var oSection = document.querySelector('section');
function majInput(oSelect) {
oInput = document.querySelector('input');
oInput.value = oSelect.value;
}
function fctSearch() {
htmlBefore = htmlBefore || oSection.innerHTML;
var oElements = oSection.querySelectorAll('span');
var ind;
var nb = oElements.length;
for (ind = 0; ind < nb; ind += 1) {
oElements[ind].classList.add('search');
}
}
function fctClear() {
if (htmlBefore.length) {
oSection.innerHTML = htmlBefore;
htmlBefore = '';
}
}
</script>
</body>
</html> |
Partager