A question about jQuery UI开发者_StackOverflow社区 dialogs. I'm creating an auto-login feature and I want to give some visual feedback. Login is done with jQuery UI dialogs.
Question: how do I force a click on the submit-button?
In the samples on the site the form hasn't got any properties set, so there must be another function triggered when the button is clicked manually.
I want to program a click on one of the buttons in a jQuery UI dialog.
Anyone that knows how to do this?
When you open the dialog you can find the buttons and add Ids on them to select using #
.
This is an option on the dialog()
function.
open: function () {
//assign ids/classes to buttons
var buttonPane$ = $(this).siblings('.ui-dialog-buttonpane');
var okButton = buttonPane$.find('button:contains("OK")');
okButton.addClass('ui-priority-primary');
okButton.attr('id', 'yourIdHere');
}
When you need to trigger the click use $('#yourIdHere').click();
Edit
If you create that as a function outside of the dialog, you can add it to the dialog options and call it directly instead of simulating a click on the button.
Apologies if I've miss understood your question,
to add a click function to things using Jquery you can use the code
('#idOfElement').click(function(){...});
However as was pointed out dialog buttons don't have id's
The way you do it is in the code that setups up your dialog...
$( "#someElement" ).dialog({
buttons: {
"text on the button": function() {
//do something
},
精彩评论