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
| <!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta http-equiv="cache-control" content="public, max-age=60">
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0">
<meta name="author" content="Daniel Hagnoul">
<title>Test</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/sunny/jquery-ui.css">
<style>
</style>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/i18n/jquery-ui-i18n.min.js"></script>
<script>
"use strict";
var
nomDesJours = [ "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" ],
nomDuJour = "inconnu"; // seconde méthode, avec une variable globale
// Première méthode, dans un input
function jourSemaine() {
let jourxxx = $( '#jourxx' ).val();
alert( jourxxx );
}
$( function(){ // forme abrégée de $(document).ready( function( ){
// setDefaults dépend de jquery-ui-i18n.min.js
$.datepicker.setDefaults( $.datepicker.regional[ "fr" ] );
$('#datexx').datepicker({
"onClose": function( dateText, inst ){
var
tabDate = dateText.split( "/" ),
year = tabDate[2],
month = parseInt( tabDate[1], 10 ) - 1,
day = parseInt( tabDate[0], 10 ),
date = new Date( year, month, day ),
dayName = nomDesJours[ date.getDay() ];
$( "#jourxx" ).val( dayName ); // remplir l'input
nomDuJour = dayName; // remplir la var globale
jourSemaine(); // test l'input
// test la var globale
setTimeout( function(){
// console, touche F12
console.log( "Nous sommes " + nomDuJour + " !" );
}, 3000 ); // 3s
}
});
});
</script>
</head>
<body>
<input id="datexx" type="text" value="">
<input id="jourxx" type="text" value="">
</body>
</html> |
Partager