
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.62 KB | hits: 12 | expires: Never
jQuery: sharing function between page code and document.ready code
<script type="text/javascript">
$(document).ready(function() {
$( "#someDialog" ).dialog({
autoOpen: false,
model: true,
buttons: {
"Do Something": function() {
var cleanInput = sanitizeInput(input);
// Do something with the clean input
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
}
});
function sanitizeInput(input) {
// Some magic here
return input;
}
});
</script>
<a href="#" onclick="doSomething('wendy');">Wendy's stats</a>
<script type="text/javascript">
function doSomething(input) {
var cleanInput = sanitizeInput(input);
// Some code here
}
</script>
$(document).ready(function() {
$( "#someDialog" ).dialog({
autoOpen: false,
model: true,
buttons: {
"Do Something": function() {
var cleanInput = sanitizeInput(input);
// Do something with the clean input
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
}
});
});
/*** Make it global ***/
function sanitizeInput(input) {
// Some magic here
return input;
}
<a href="#" onclick="doSomething('wendy');">Wendy's stats</a>
<a href="#" data-name="wendy or server var">Wendy's stats</a>
$("a[data-name]").click(function (e) {
e.preventDefault();
doSomething($(this).data("name"));
});