在所有jQuery选项卡中包含相同的jsp页面
Include same jsp page in all jQuery tabs
我想在所有具有唯一选项卡ID的jQuery选项卡中包含相同的JSP页面,即在CommentTab.html的所有jQuery选项卡上包含相同的Comment.JSP文件。当我运行以下代码时,我可以创建新的选项卡,但JSP页面内容不会显示在任何选项卡中
<script>
$(function() {
var tabTitle = $( "#tab_title" ),
tabContent = $( "#tab_content" ),
tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>",
tabCounter = 2;
var tabs = $( "#tabs" ).tabs();
// modal dialog init: custom buttons and a "close" callback reseting the form inside
var dialog = $( "#dialog" ).dialog({
autoOpen: false,
modal: true,
buttons: {
Add: function() {
addTab();
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
form[ 0 ].reset();
}
});
// addTab form: calls addTab function on submit and closes the dialog
var form = dialog.find( "form" ).submit(function( event ) {
addTab();
dialog.dialog( "close" );
event.preventDefault();
});
// actual addTab function: adds new tab using the input from the form above
function addTab() {
var label = tabTitle.val() || "Tab " + tabCounter,
id = "tabs-" + tabCounter,
li = $( tabTemplate.replace( /#'{href'}/g, "#" + id ).replace( /#'{label'}/g, label ) ),
//tabContentHtml = tabContent.val() || "Tab " + tabCounter + " content.";
tabContentHtml = getComments();
tabs.find( ".ui-tabs-nav" ).append( li );
tabs.append( "<div id='" + id + "'><p>" + tabContentHtml + "</p></div>" );
tabs.tabs( "refresh" );
tabCounter++;
}
function getComments(){
$( "#success" ).load( "Comment.jsp", function( response, status, xhr ) {
if ( status == "error" ) {
var msg = "Sorry but there was an error: ";
$( "#error" ).html( msg + xhr.status + " " + xhr.statusText );
}
});
}
// addTab button: just opens the dialog
$( "#add_tab" )
.button()
.click(function() {
dialog.dialog( "open" );
});
// close icon: removing the tab on click
$( "#tabs span.ui-icon-close" ).live( "click", function() {
var panelId = $( this ).closest( "li" ).remove().attr( "aria-controls" );
$( "#" + panelId ).remove();
tabs.tabs( "refresh" );
});
});
</script>
<body>
<div id="dialog" title="Tab data">
<form>
<fieldset class="ui-helper-reset">
<label for="tab_title">Title</label> <input type="text"
name="tab_title" id="tab_title" value=""
class="ui-widget-content ui-corner-all" />
<div id="tab_content" class="ui-widget-content ui-corner-all"></div>
</fieldset>
</form>
</div>
<button id="add_tab">Add Tab</button>
<div id="tabs">
<ul>
<div id="success"></div>
</ul>
使用iframe解决了问题。代码的修改部分如下:脚本部分:
<script>
$(function() {
var tabTitle = $( "#tab_title" ),
tabContent = $( "#tab_content" ),
tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>",
tabCounter = 2;
var websiteframe = '<iframe src="Comment.jsp" width="100%" height="100%" allowtransparency="true" frameBorder="0">Your browser does not support IFRAME</iframe>';
var tabs = $( "#tabs" ).tabs();
然后将websiteframe包含在addTab函数中:
function addTab() {
var label = tabTitle.val() || "Tab " + tabCounter,
id = "tabs-" + tabCounter,
li = $( tabTemplate.replace( /#'{href'}/g, "#" + id ).replace( /#'{label'}/g, label ) ),
websiteframe = '<iframe src="Comment.jsp" width="100%" height="100%" allowtransparency="true" frameBorder="0">Your browser does not support IFRAME</iframe>';
tabs.find( ".ui-tabs-nav" ).append( li );
tabs.append( "<div id='" + id + "'>" + websiteframe + "</div>" );
tabs.tabs( "refresh" );
tabCounter++;
}
html部分:
<button id="add_tab">Add Tab</button>
<div id="tabs">
<ul>
</ul>
</div>
相关文章:
- 使用Javascript生成包含JSP的HTML
- 在使用cq:include包含外部JS之前,如何在JSP中包含全局JS变量
- 需要帮助获取javascript中包含的jsp页面的名称
- 如何在jsp页面中包含一个拖放交互UI
- 在JSP中包含java脚本路径
- 如何在 jsp 页面中包含 javascript
- 在包含的 JSP 页面中获取 JSP 变量
- 获取 js 中包含 jsp 的值
- 如何从其他 jsp 调用方法/函数以包含在另一个 jsp 的 jstree 中
- jquery选项卡-将内容从包含的jsp切换到另一个jsp
- 在所有jQuery选项卡中包含相同的jsp页面
- javascript可以包含在JSP中吗
- 将选中绑定与包含元素上的单击绑定相结合
- 在JSP上显示包含可变长度<td>
- 我不能在我的JSP页面中包含javaScript和css
- 通过JSP:param将Java List传递到包含的JSP
- STS Spring MVC:如何在JSP中包含JS文件
- 如何将JavaScript文件包含到JSP中
- 当单击按钮时,将一个jsp包含在另一个jsp中
- 如何使用javascript将一个jsp包含在另一个jsp中