gpt4 book ai didi

javascript - Jquery 模式无法正常工作

转载 作者:行者123 更新时间:2023-11-30 11:23:57 26 4
gpt4 key购买 nike

我正在尝试使用 jquery ui 模式,但它不能满足我的需要,即,我想仅在模式内部显示数据,但在这里它在我单击按钮之前显示。

function pop_up()
{
var dialog, form
dialog = $('div#infoDialog').dialog({
autoOpen: false,
height: 600,
width: 500,
modal: true
});
$('#showInfos').click(function(e){
e.preventDefault();
dialog.dialog('open');
});
}
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/redmond/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<button type="button" id="showInfos" onclick="pop_up();">test</button>
<div id="infoDialog" title="Eventinfos">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
</p>
</div>

最佳答案

您的代码几乎是正确的,您的代码中只有一个错误,那就是您将所有 javascript 代码与 onclick 事件绑定(bind)在一起,这就是它默认显示模式内容的原因。 所以现在你只需删除 onclick 事件和 pop_up() 函数即可。所以你的最终代码将如下所示。

<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>

<script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>

<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />

<button type="button" id="showInfos" >test</button>
<div id="infoDialog" title="Eventinfos">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum

</p>
</div>

<script>
// function pop_up()
// {
var dialog, form
dialog = $('div#infoDialog').dialog({
autoOpen: false,
height: 600,
width: 500,
modal: true
});
$('#showInfos').click(function(e){
e.preventDefault();
dialog.dialog('open');
});
// }
</script>

关于javascript - Jquery 模式无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48739562/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com