In my spelling game, when a letter is complete I want the next word to spell to be selected automatically. At the moment the user has to click the button to go to the next.
At the moment I have this
var noExist = $('td[data-word=' + listOfWords[rndWord].name + ']').hasClass('wordglow2');
if (noExist) {
$('.minibutton').click('enable');
} else {
$('.minibutton').click('disable');
$("#mysoundclip").attr('src', listOfWords[rndWord].audio);
audio.play();
$("#mypic").attr('src', listOfWords[rndWord].pic);
pic.show();
}
});
I have tried replacing the line...
$('.minibutton').click('enable');
to...
$('.minibutton').trigger('click')
and it won't work, any ideas?
THANKS
You should consider refactoring so that the action of going to the next word is independent of how it is triggered. That would be cleaner and you don't have to do tricks like faking clicks.
function gotoNextWord(){
// ...
}
and setup
$('.minibutton').on('click', gotoNextWord);
and I'm not entirely grokking your code, but it would become something like this:
// ...
if (noExist) {
gotoNextWord();
} else {
// ...
}
怎么样: $('.minibutton').click();
to Disable
$('.minibutton').unbind('click').click(function(e){
e.preventDefault();
});
to enable
$('.minibutton').unbind('click');
Try this
if (noExist) {
$('.minibutton').click('enable'); // if your button successfully enable then write below line after it.
$('.minibutton').click();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.