gpt4 book ai didi

javascript - 如何在单击上下文菜单中的选项时显示模式对话框?

转载 作者:行者123 更新时间:2023-11-28 07:33:33 24 4
gpt4 key购买 nike

当我从上下文菜单(源自 jsplumb 流程图组件内部)中选择一个选项(在我的例子中为“配置”选项)时,我需要弹出一个模式对话框。我有“userlogged.jsp”,这是流程图组件出现的地方。 “demo.js”是上下文菜单功能所在的位置。 “index.jsp”只有我需要显示在 userLogged.jsp 内容之上的模式。

这是 demo.js 的一部分

   $(function() {
$.contextMenu({
selector : '.context-menu-one',
callback : function(key, options) {
$(document)
.ready(
function() {
fromMenu();

});
if (key == "configure") {

fromMenu();
}
},
items : {
"configure" : {
name : "configure",
icon : "edit"
},
"delete" : {
name : "Delete",
icon : "delete"
}
}
});
});

这是index.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<!doctype html>
<!--[if IE 9]><html class="lt-ie10" lang="en" > <![endif]-->
<html class="no-js" lang="en"
data-useragent="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<meta name="description"
content="Documentation and reference library for ZURB Foundation. JavaScript, CSS, components, grid and more." />
<meta name="author"
content="ZURB, inc. ZURB network also includes zurb.com" />
<meta name="copyright" content="ZURB, inc. Copyright (c) 2015" />
<link rel="stylesheet" href="src/css/foundation.css" />
<script src="src/js/modernizr.js"></script>
<script src="src/js/jquery.js"></script>
<script type="text/javascript">
$(document)
.ready(
function() {

$('#firstModal').foundation('reveal', 'open');

//checks for the button click event
$("#sec")
.click(
function(e) {
var username = $("input#username")
.val();
var root = $("input#root").val();
var password = $("input#password")
.val();
var db = $("input#db").val();
var port = $("input#port").val();
dataString = "username=" + username
+ "&root=" + root
+ "&password=" + password
+ "&db=" + db + "&port="
+ port;
$.ajax({
type : "GET",
url : "DbInformation",
data : dataString,
success : function(data) {
var data = JSON.parse(data);
alert(data);
console.log(data.length);
$("#countrytable").find("tr:gt(0)").remove();
var table1 = $("#countrytable");
for ( var i = 0; i < data.length; i++) {
var rowNew = $("<tr><td></td></tr>");
rowNew.children().eq(0).html(("<select id='tabl' name=mytextarea size=3 height = '20px' ><option name=one value="+data[i]+">"+ data[i] + "</option></select>"));
rowNew.appendTo(table1);
}
}
});
});
$("#third").click(
function(e) {
var tabl = $("#tabl").val();
var username = $("input#username").val();
var root = $("input#root").val();
var password = $("input#password").val();
var db = $("input#db").val();
var port = $("input#port").val();
dataString = "username=" + username
+ "&root=" + root + "&password="
+ password + "&db=" + db + "&port="
+ port + "&tabl=" + tabl;
$.ajax({
type : "GET",
url : "DbInformation",
data : dataString,
success : function(data) {
var data = JSON.parse(data);
alert(data);
var dd = "";
console.log(data.length);
$("#columns").find("tr:gt(0)").remove();
var table1 = $("#columns");
for ( var i = 0; i < data.length; i++) {
var rowNew = $("<tr><td></td></tr>");
rowNew.children().eq(0).html(("<select id='tabl' name=mytextarea size=3 height = '20px' ><option name=one value="+data[i]+">"+ data[i] + "</option></select>"));
rowNew.appendTo(table1);
}
}
});
});
});
</script>
</head>
<body>



<div id="firstModal" class="reveal-modal tiny" data-reveal>
<h2>Properties.</h2>
<p>
Username : <input type="text" id="username" name="username"
value="">
</p>
<p>
root : <input type="text" id="root" name="root" value="">
</p>
<p>
password : <input type="text" id="password" name="password"
value="">
</p>
<p>
db : <input type="text" id="db" name="db" value="">
</p>
<p>
port : <input type="text" id="port" name="port" value="3306">
</p>
<p>
<a href="#" id="sec" data-reveal-id="secondModal"
class="secondary button">Next</a>
</p>
<a class="close-reveal-modal">&#215;</a>
</div>

<div id="secondModal" class="reveal-modal tiny" data-reveal>
<h2>This is a second modal.</h2>
<table id="countrytable">
<tr>
<th scope="col">Table name</th>
</tr>
</table>
<p>
<a href="#" id="third" data-reveal-id="thirdModal"
class="third button">Next</a>
</p>
<a class="close-reveal-modal">&#215;</a>
</div>

<div id="thirdModal" class="reveal-modal tiny" data-reveal>
<h2>This is a second modal.</h2>
<table id="columns">
<tr>
<th scope="col">Column name</th>
</tr>
</table>
<p>
<a href="#" id="fourth" data-reveal-id="thirdModal"
class="fourth button">Finish</a>
</p>
<a class="close-reveal-modal">&#215;</a>
</div>




<script src="src/js/foundation.js"></script>
<script src="src/js/foundation.tab.js"></script>
<script src="src/js/foundation.reveal.js"></script>
<script>
$(document).foundation();
var doc = document.documentElement;
doc.setAttribute('data-useragent', navigator.userAgent);
</script>
</body>
</html>

如何在单击 demo.js 中定义的上下文菜单中的配置选项时,使在 index.jsp 中生成的模式显示在 userlogged.jsp 的顶部

最佳答案

如果您希望模式对话框位于“userlogged.jsp”的内容之上,那么我认为您应该将代码(用于模式对话框)放在该页面本身中,因为如果它导航到单独的页面(例如index.html), jsp)那么它就不会是一个模态对话框(因为它已经导航到另一个页面)。

一种方法是在父页面本身中包含模式对话框 HTML 代码(如果我没记错的话,在您的情况下是“userlogged.jsp”),将其可见性设置为隐藏(以便默认情况下不显示) )并在触发特定事件(例如单击特定上下文菜单)时,将可见性设置为正常(以便它在现有页面上作为模式对话框出现)。还要确保在某个事件(例如单击模式对话框上的“确定”按钮)上也注意删除该模式(通过将可见性设置为隐藏)。

希望对你有帮助!

关于javascript - 如何在单击上下文菜单中的选项时显示模式对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28852429/

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