想要在按钮
上打开onclick()事件的对话框file.html
<div class="new"></div>
<div id="dialog" title="Basic dialog">
<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<script>
$(function() {
$(".new").append('<div class="butn"><input type= "button"class ="btn btn-info " onclick="dialogopen()" value= "Reply"><>');
});
$("#dialog").dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
function dialogopen() {
alert("hello new");
$("#dialog").dialog("open");
}
</script>
我做错了什么我不知道。请帮帮我。
答案 0 :(得分:1)
关闭)
功能时您还有dialogopen
,需要将其删除
function dialogopen() {
alert("hello new");
$("#dialog").dialog("open");
//});
}; //Removed ) in this line
此外,您应该使用Event Delegation委托事件方法.on()来动态元素而不是内联事件处理程序。
即
$(document).on('event','selector',callback_function)
实施例
$(document).on('click', ".btn-info", function(){
$("#dialog").dialog("open");
});
答案 1 :(得分:1)
你有一个额外的)
function dialogopen() {
alert("hello new");
$( "#dialog" ).dialog( "open" );
}
答案 2 :(得分:0)
试试这个。
$(".new")
.append('<div class="butn"><input type= "button"class ="btn btn-info " value= "Reply"><>')
.bind('click', function() {
dialogopen();
})
和
function dialogopen() {
alert("hello new");
$( "#dialog" ).dialog( "open" );
};