<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('input[name="rdo_test"]').each(
function(index){
$(this).bind(
"click",function()
{
alert("index: " + index + " value = " + $(this).val())
}
) // end bind
} // end function
) // end each
// dynamic field test
$('<input type="radio" name="rdo_test" value="4" />Test 4<br />').appendTo('body');
});
</script>
</head>
<body>
<input type="radio" name="rdo_test" value="1" />Test 1<br />
<input type="radio" name="rdo_test" value="2" />Test 2<br />
<input type="radio" name="rdo_test" value="3" />Test 3<br />
</body>
</html>
$('input[name="rdo_test"]').live("click",function(){
alert("index: " + $(this).index('input[name="rdo_test"]') + " value = " + $(this).val())
})
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('input[name="rdo_test"]').live("click",function(){
alert("index: " + $(this).index('input[name="rdo_test"]') + " value = " + $(this).val())
})
// dynamic field test
$('<input type="radio" name="rdo_test" value="4" />Test 4<br />').appendTo('body');
});
</script>
</head>
<body>
<input type="radio" name="rdo_test" value="1" />Test 1<br />
<input type="radio" name="rdo_test" value="2" />Test 2<br />
<input type="radio" name="rdo_test" value="3" />Test 3<br />
</body>
</html>
ASKER
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.
TRUSTED BY