当我从上下文菜单(源自jsplumb流程图组件内部)中选择一个选项(在我的情况下为“configure”选项)时,我需要弹出一个模态对话框。我有“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">×</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">×</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">×</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中定义的上下文菜单中单击configure选项时,将index.jsp中生成的此模态显示在userlogged.jsp之上
答案 0 :(得分:0)
如果你想要模式对话框覆盖&#34; userlogged.jsp&#34;的内容,那么我认为你应该把代码(用于模态对话框)放在那个页面本身,因为如果它导航到一个单独的页面(如index.jsp)然后它不会成为一个模态对话框(因为它已经已经导航到另一个页面)。
这样做的一种方法是在父页面本身中使用模态对话框HTML代码(例如,#34; userlogged.jsp&#34;在你的情况下,如果我没有错),将其可见性设置为隐藏(以便默认情况下它并不显示)和触发特定事件(如点击特定上下文菜单),将可见性设置为正常(以便它作为现有页面上的模态对话框出现)。 另外,请确保在某个事件上(例如在模态对话框中单击&#34;确定&#34;按钮)处理删除该模态(通过将可见性设置为隐藏)。
希望它有所帮助!