Kategori: CSS

.reset() form jQuery

Lakukan:


$('#idForm')[0].reset();

nilai pada input didalam form dengan id=’idForm’ di reset.

Source code nya:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type='text/javascript' src='jquery.js'></script>
<script type='text/javascript'>
$(document).ready(function(){
$('#b_refresh').click(function(){
$('#idForm')[0].reset();
});
});
</script>
</head>
<body>
<form id='idForm'>
Nama: <input type='text' name='nama' value=''><br>
Alamat: <input type='text' name='nama' value=''><br>
No. Telpon: <input type='text' name='nama' value=''><br>
Gaji: <input type='text' name='nama' value=''><br>
<input type='submit' value='Go'>&nbsp;<input type='button' id='b_refresh' value='Reset'>
</form>
</body>
</html>

Demo disini.

Corat-coret 06 – jquery.live()

Dengan menggunakan jquery.live():

$(".tombol_dgn").live("click", function(){
$('#dgn_live').after("<button class='tombol_dgn'>Tombol dengan live</button>");
});

Dengan menggunakan jquery.click():

$(".tombol_bkn").click(function(){
$('#bkn_live').after("<button class='tombol_bkn'>Tombol tanpa live</button>");
});

Skrip lengkap untuk demo:

<html>
<head>
<title>Live Jquery</title>
<script src='jquery.js' type='text/javascript'></script>
<script type='text/javascript'>
$(document).ready(function(){
$(".tombol_dgn").live("click", function(){
$('#dgn_live').after("<button class='tombol_dgn'>Tombol dengan live</button>");
});

$(".tombol_bkn").click(function(){
$('#bkn_live').after("<button class='tombol_bkn'>Tombol tanpa live</button>");
});
});
</script>
</head>
<body>
<div id='dgn_live'>
<button class='tombol_dgn'>Tombol dengan live</button>
</div>
<div id='bkn_live'>
<button class='tombol_bkn'>Tombol tanpa live</button>
</div>
</body>
</html>

Lihat Demo