jQuery .click event not Working
Here is script I used
<script type="text/javascript">
$(document).ready(function() {
$("#dialog").dialog({
autoOpen: true,
height: 300,
width: 350,
modal: true,
buttons: {
'Calling': function(){},
'Cancel' : function(){
$(this).dialog('close');
}
}
开发者_开发问答 });
$('#id_call').click(function() {
$("#dialog").dialog("open");
});
});
</script>
In this one button is used to show the dialog
<button id="id_call">Click to Call</button>
But click event is not working...
Can you bind the event like this instead?
$('#id_call').bind('click', function() { $("#dialog").dialog("open"); });
you can try this: http://jsfiddle.net/K2C4n/
I changed autoOpen: false
HTML:
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<button id="id_call">Click to Call</button>
<div id="dialog" title="Dialog Title">I'm in a dialog</div>
</body>
</html>
jQuery:
$(document).ready(function() {
$("#dialog").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
'Calling': function(){},
'Cancel' : function(){
$(this).dialog('close');
}
}
});
$('#id_call').click(function() {
$("#dialog").dialog("open");
});
});
EDIT: Don't forget to include jQuery and jQueryUI.
It's possible you may have another HTML node with the same ID? jQuery essentially uses .getElementyById() which only returns one node for that ID regardless of how many nodes have that particular ID.
精彩评论