Created
May 17, 2010 13:33
-
-
Save mdales/403761 to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | |
<title>closuretest</title> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"> | |
</script> | |
<script> | |
var list = [ | |
{name: 'foo', val: 42}, | |
{name: 'bar', val: 32} | |
]; | |
function setclick(obj) | |
{ | |
$("button#" + obj.name).click(function() | |
{ | |
console.log(obj); | |
} | |
); | |
} | |
$(document).ready(function() | |
{ | |
var idx; | |
for (idx in list) | |
{ | |
var info = list[idx]; | |
$("#testarea").append('<button id="' + info.name + '">Test</button>'); | |
setclick(info); | |
} | |
} | |
); | |
</script> | |
</head> | |
<body id="closuretest"> | |
<div id="testarea"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment