marp | title | paginate | author |
---|---|---|---|
false |
Fondamenti |
true |
mauro |
Mauro Bogliaccino
Molto utili per guidare l'utente nella compilazione e segnalare degli errori.
<li>
<label>Nome</label>
<input type="text" id="nome" name="nome" class="obbligatorio" />
</li>
<li>
<label>Indirizzo</label>
<input type="text" id="indirizzo" name="indirizzo "/>
</li>
<li>
<label>Email</label>
<input type="text" id="email" name="email" class="obbligatorio" />
</li>
<li>
<input type="button" id="invia" name="invia" value="invia" onclick="controlla()" />
</li>
function controlla(){
$(".obbligatorio ").each( function(){
if( ($(this).val()=="") ){
errore=true;
$(this).prev().addClass('rosso');
}
else{
$(this).prev().removeClass('rosso');
}})
if(errore==true) {
alert("Il form contiene errore/i, si prega di correggere.");
}
else {
alert("Complimenti! Non ci sono errori!");
}
}
</script>
$('a.top').click(function(){
$(document.body).animate({scrollTop : 0},800);
return false;
});
<a class="top" href="#">Back to top</a>
$('img').load(function() {
console.log('image load successful');
});
$('img').error(function(){
$(this).attr('src', 'img/broken.png');
});
$('.btn').hover(function(){
$(this).addClass('hover');
}, function(){
$(this).removeClass('hover');
}
);
$('input[type="submit"]').attr("disabled", true);
$('input[type="submit"]').removeAttr("disabled");
$('a.no-link').click(function(e){
e.preventDefault();
});
// Fade
$( “.btn" ).click(function() {
$( “.element" ).fadeToggle("slow");
});
// Toggle
$( “.btn" ).click(function() {
$( “.element" ).slideToggle("slow");
});
// Close all Panels
$('#accordion').find('.content').hide();
// Accordion
$('#accordion').find('.accordion-header').click(function(){
var next = $(this).next();
next.slideToggle('fast');
$('.content').not(next).slideUp('fast');
return false;
});
$('.div').css('min-height', $('.main-div').height());
$('li:odd').css('background', '#E8E8E8');
jQuery( document ).ready(function() {
jQuery.get( "mypage.php", { name: "John", time: "2pm" } )
.done(function( data ) {
alert( "Data Loaded: " + data );
});
});
jQuery("button").click(function(){
jQuery.post("page.php", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
<ol id="new-projects"></ol>
<script>
jQuery( document ).ready(function() {
jQuery( "#new-projects" ).load( "/resources/load.html #projects li" );
});
</script>
jQuery( document ).ready(function() {
jQuery( "#submit" ).click(function() {
jQuery.post( "https://yoursite.com/yourpage.php", jQuery('#form').serialize())
.done(function( data ) {
alert(data);
});
return false;
});
});
jQuery.getJSON( "http://yoursite.com/test.json", function( data ) {
alert(data);
});
jQuery.getJSON( "http://yoursite.com/test.json", function( data ) {
var obj = JSON.parse(data);
jQuery( "#container" ).html(obj.name + ", " + obj.age);
});
$("#link1").click(function(){
$("#p").show();
$("#p").children().show();
});
$("#link2").click(function(){
$("#small1").hide();
});
$("#link3").click(function(){
$("#middle2").hide();
});
var divs = $( "div" ).get();
divs = divs.concat( $( ".test1" ).get() );
$( "div:eq(1)" ).text( "This is cool " + divs.length + " element." );
divs = jQuery.unique( divs );
$( "div:eq(2)" ).text( "jQuery is very fun to" + divs.length + " learn.." )
.css( "color", "blue" );
// Ordinare un array di elementi del DOM, rimuovendoi duplicati. Non funziona con stringhe o numeri
$(document).ready(function(){
$("button").click(function(){
var txt = "";
txt += "Width of div: " + $("#div1").width() + "
";
txt += "Height of div: " + $("#div1").height() + "
";
txt += "Outer width of div (margin included): " + $("#div1").outerWidth(true) + "
";
txt += "Outer height of div (margin included): " + $("#div1").outerHeight(true);
$("#div1").html(txt);
});
});
$(document).ready(function(){
$("button").click(function(){
$("li").each(function(){
alert($(this).text())
});
});
});
$(document).ready(function(){
/*! Fades in whole page on load */
$('body').css('display', 'none');
$('body').fadeIn(500);
});
var tId;
$('input[type="checkbox"]').change(function(){
clearTimeout(tId);
tId=setTimeout(function(){
$('#top_header_form').submit();
},650);
});
$("button").click(function(){
$.getJSON("demo_json.js", function(result){
$.each(result, function(i, field){
$("div").append(field + " ");
});
});
});
$(document).ready(function() {
$('a[href^="http://"],a[href^="https://"]')
.attr('target','_blank')
.addClass('ext_link')
;
});
$(function() {
$( 'ul.nav li' ).on( 'click', function() {
$( this ).parent().find( 'li.active' ).removeClass( 'active' );
$( this ).addClass( 'active' );
});
});