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
| <!DOCTYPE html>
<html lang="fr-FR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Délégation événement sur liste</title>
<style>
html, body {
margin: 0;
padding: 0;
font: 1em/1.5 Verdana,sans-serif;
}
main {
display: block;
margin: 0 auto;
max-width: 60em;
}
h1, h2, h3 {
color: #069;
}
button {
font: inherit;
padding: .25em 1em;
cursor: pointer;
}
#info {
border-left: 3px solid #080;
text-indent: 1em;
}
ul {
width: 15em;
padding: 2px;
border: 1px solid #CCC;
list-style: none;
}
li {
padding: .25em;
border: 1px solid #FFF;
border-radius: 3px;
cursor: pointer;
}
li:hover {
border: 1px solid #ABC;
background: #DEF;
}
</style>
</head>
<body>
<main>
<h1>Délégation événement sur liste</h1>
<p id="info">Aucune sélection</p>
<p><button id="btn">AddItem</button></p>
<ul id="list">
<li>Item #1</li>
<li>Item #2</li>
<li>Item #3</li>
</ul>
</main>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<script>
require(["dojo/dom", "dojo/on", "dojo/dom-construct"], function (dom, on, domConstruct) {
function addItem(id) {
var oList = dom.byId(id);
var num = oList.children.length;
domConstruct.create("li", {
innerHTML: "Item #" + (num + 1)
}, oList);
}
on(dom.byId("list"), "click", function (e) {
var oSrce = e.target;
if (oSrce.tagName === "LI") {
var oDest = dom.byId("info");
oDest.textContent = "Sélection de " + oSrce.textContent;
}
});
on(dom.byId("btn"), "click", function (e) {
addItem("list");
});
});
</script>
</body>
</html> |
Partager