combining two jquery functions
function alt开发者_如何学Gocat(id) {
$ogzu = id;
}
function okaycity(id) {
jQuery("#okay").load("ajax_post_category.php?okay="+id+"");
$ugur = id;
}
how can i combine these two functions? i want them to work like as one function. i tried so many ways, however couldnt done it.i googled, couldnt find a way. can anyone save me? regards
function altcat(id) {
$ogzu = id;
}
function okaycity(id) {
jQuery("#okay").load("ajax_post_category.php?okay="+id+"");
$ugur = id;
}
function combined(id) {
altcat(id);
okaycity(id);
}
I'm confused :-S
I may be misunderstanding the question:
function combinedVersion(id) {
$ogzu = id;
jQuery("#okay").load("ajax_post_category.php?okay="+id+"");
$ugur = id;
}
If you want to preserve their earlier names (because something is calling them by that name, and you can't update it to use a new name), you can add this to the above:
var altcat = combinedVersion;
var okaycity = combinedVersion;
Then, calling altcat()
, okaycity()
, or combinedVersion()
will all call the same function. You will want to make sure that the two var
statements there are above things that may use them. At the top of the function (if this is within a function) or page (if it's at global scope) would be best.
So if this is at global scope:
<script type='text/javascript'>
var altcat = combinedVersion;
var okaycity = combinedVersion;
function combinedVersion(id) {
$ogzu = id;
jQuery("#okay").load("ajax_post_category.php?okay="+id+"");
$ugur = id;
}
</script>
...or if it's inside a function:
function foo() {
var altcat = combinedVersion;
var okaycity = combinedVersion;
function combinedVersion(id) {
$ogzu = id;
jQuery("#okay").load("ajax_post_category.php?okay="+id+"");
$ugur = id;
}
}
精彩评论