Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
first commit
- Loading branch information
airportyh
authored and
airportyh
committed
Jul 20, 2009
0 parents
commit f5dfd26
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(function(){ | ||
function jRadio(name){ | ||
this.elements = $('input[type=radio][name=' + name + ']'); | ||
this.lastVal = jRadio.prototype.val.apply(this); | ||
} | ||
jRadio.prototype.change = function(callback){ | ||
var self = this; | ||
this.elements.click(function(){ | ||
var val = self.val(); | ||
if (val != self.lastVal){ | ||
self.lastVal = val; | ||
callback(self); | ||
} | ||
}) | ||
} | ||
jRadio.prototype.val = function(val){ | ||
if (val === undefined){ | ||
return this.elements.filter(function(){ return this.checked; }).val(); | ||
}else{ | ||
if (this.lastVal == val) return; | ||
this.lastVal = val; | ||
this.elements.filter(function(){ return $(this).val() == val; }).attr('checked', true); | ||
return this; | ||
} | ||
} | ||
|
||
$.radio = function(name){ | ||
return new jRadio(name); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE PUBLIC "-//W3c//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | ||
<script type="text/javascript" src="jquery.js"></script> | ||
<script type="text/javascript" src="jradio.js"></script> | ||
<script type="text/javascript"> | ||
<!-- | ||
|
||
|
||
|
||
$(function(){ | ||
$.radio('radio').change(function(ui){ | ||
console.log('Radio button changed to ' + ui.val()); | ||
}) | ||
}) | ||
--> | ||
</script> | ||
<title>Test jRadio</title> | ||
|
||
</head> | ||
<body> | ||
<label>One: </label><input type="radio" name="radio" value="one"><br> | ||
<label>Two: </label><input type="radio" name="radio" value="two"> | ||
</body> | ||
</html> |