Jquery ui jQuery.click事件不工作
这是我使用的脚本Jquery ui jQuery.click事件不工作,jquery-ui,Jquery Ui,这是我使用的脚本 <script type="text/javascript"> $(document).ready(function() { $("#dialog").dialog({ autoOpen: true, height: 300, width: 350, modal: true, buttons: { 'Calling': function(){}, 'Cancel' : function(){
<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>
在这种情况下,一个按钮用于显示对话框
<button id="id_call">Click to Call</button>
但是单击事件不起作用 您可以这样绑定事件吗
$('#id_call').bind('click', function() { $("#dialog").dialog("open"); });
您可以尝试以下方法:
我更改了自动打开:false
HTML:
编辑:别忘了包括jQuery和jQueryUI。您可能有另一个具有相同ID的HTML节点?jQuery本质上使用.getElementyById,它只为该ID返回一个节点,而不管有多少节点具有该特定ID。我们可以看到相应的标记位吗?对话框是无法打开,还是单击事件根本没有触发?工作正常,但即使您将其更改为自动打开:true,它似乎仍然可以工作,尽管在加载时也是如此!如果将autoOpen更改为true或false,则会产生不同的结果。如果为true,则对话框立即显示;如果为false,则对话框仅在单击按钮时显示。同意,但即使设置为true,也会在单击时工作,因此@ashok可能没有遇到问题?
<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>
$(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");
});
});