Very simple function, but doesn't work
Please tell me what is the problem in this script:
$("#mydiv").click(function()
{
console.log("something");
}, function()
{
console.log("something");
});
It doesn't make second console
.
Thanks
click
only takes one function. What are you expecting out of the second function?
To have the second function run after the first function, just put it at the end of the first function. If the first function does something asynchronously, then you'll need to attach your second function as a callback to the first's result.
$('#mydiv').click(function () {
console.log('first something');
console.log('second something');
});
or maybe like:
$('#mydiv').click(function () {
$(this).fadeOut(function () {
console.log('second something');
});
});
You can probably just write your two functions as actual functions, then call each in order from your anonymous functions. Like this:
function a()
{
console.log("something");
}
function b()
{
console.log("something");
}
$("#id").click(function(){
a();
b();
});
I don't think you can bind two functions on one event like this. Unless it is designed for it, like hover for example.
As mentioned above click
takes only one handler at time. I guess you need to call it twice:
$("#mydiv").click(function()
{
console.log("something 1");
});
$("#mydiv").click(function()
{
console.log("something 2");
});
There is nothing here to execute the second anonymous (unnamed) function.
EDIT: IF what you want is to bind the two actions of a "click" you can bind the .mousedown and .mouseup functions instead of the singlular .click
EDIT2: Based on comments, produce a private, sequence of execution functions:
$('#mybutton').click(function(){
var one = function(){
alert('one');
};
var two= function(){
alert('two');
};
one();
two();
});
To see this in action visit: http://jsfiddle.net/R7aT3/
精彩评论