这是一个分为两部分的问题,因此,如果这不是正确的处理方式,我深表歉意。好的,只要您按一下按钮,就会创建我的标签页,并且它们的内容都有唯一的ID。我要弄清楚的是,如何保存我的标签列表并在下次访问该页面时甚至已经打开它们,甚至重新启动该应用程序。其次,我的应用是通过ASP.NET MVC创建的。我的理解是,保存选项卡需要将信息以及该人的UserID一起保存到数据库的表中,该信息可以通过Windows身份验证生成。但是,我不确定如何实现。我已尽力按照以下链接进行尝试,但不确定其设置是否正确。
不幸的是,如果有必要查看我的代码,我目前无法这样做。我可以说这主要是将数据插入数据库中,然后将其用于显示在页面上。这是一个小提琴,通常可以显示当前的所有设置:https://jsfiddle.net/fu3xh95L/36/?fbclid=IwAR0YeVmJjB11vbI2X1j9VQB_90LU742Phj51Tcap6RAad-zuFNr65VMS97Q
任何帮助将不胜感激:)。
// A $( document ).ready() block.
$( document ).ready(function() {
console.log( "ready!" );
$('#myButton').on('click', function() {
// List name
var e = document.getElementById("listSelect");
var listName = e.options[e.selectedIndex].value;
var number = null;
var matches = listName.match(/(\d+)/);
if (matches) {
number = matches[0];
} else {
alert("Number not found");
return;
}
var listID = "List"+number;
var tableID = listID+"TB";
// Create list item
// Create attributes
var roleAtt = document.createAttribute("role"); // Create a "role" attribute
roleAtt.value = "presentation"; // Set the value of the role attribute
var li = document.createElement('li');
li.setAttributeNode(roleAtt); // Add the role attribute to <li>
// Create link item
var a = document.createElement('a');
// Create attributes
var hrefAtt = document.createAttribute("href"); // Create a "role" attribute
hrefAtt.value = "#"+listID; // Set the value of the role attribute
var acAtt = document.createAttribute("aria-controls"); // Create a "role" attribute
acAtt.value = "home"; // Set the value of the role attribute
var roleAtt = document.createAttribute("role"); // Create a "role" attribute
roleAtt.value = "tab"; // Set the value of the role attribute
var dtAtt = document.createAttribute("data-toggle"); // Create a "role" attribute
dtAtt.value = "tab"; // Set the value of the role attribute
var text = document.createTextNode(listName);
var a = document.createElement('a');
a.appendChild(text);
a.setAttributeNode(hrefAtt);
a.setAttributeNode(acAtt);
a.setAttributeNode(roleAtt);
a.setAttributeNode(dtAtt);
li.appendChild(a);
parentElement = document.getElementById("tabTitles");
parentElement.insertBefore(li, parentElement.children[1]);
//<div role="tabpanel" class="tab-pane" id="home">Home</div>
var tabContentDiv = document.createElement('div');
var roleAtt = document.createAttribute("role"); // Create a "role" attribute
roleAtt.value = "tabpanel"; // Set the value of the role attribute
var classAtt = document.createAttribute("class"); // Create a "role" attribute
classAtt.value = "tab-pane"; // Set the value of the role attribute
var idAtt = document.createAttribute("id"); // Create a "role" attribute
idAtt.value = listID; // Set the value of the role attribute
var text = document.createTextNode(listName);
tabContentDiv.appendChild(text);
tabContentDiv.setAttributeNode(roleAtt);
tabContentDiv.setAttributeNode(classAtt);
tabContentDiv.setAttributeNode(idAtt);
// Create table
var tabContentTable = document.createElement('table');
var idAtt = document.createAttribute("id"); // Create a "role" attribute
idAtt.value = tableID; // Set the value of the role attribute
var classAtt = document.createAttribute("class"); // Create a "role" attribute
classAtt.value = "display"; // Set the value of the role attribute
var styleAtt = document.createAttribute("style"); // Create a "role" attribute
styleAtt.value = "width:100%"; // Set the value of the role attribute
var tabContentTableHead = document.createElement('thead');
var tabContentTableRow = document.createElement('tr');
var tabContentTableHeader = document.createElement('th');
var text = document.createTextNode("First name");
tabContentTableHeader.appendChild(text);
tabContentTableRow.appendChild(tabContentTableHeader);
tabContentTableHead.appendChild(tabContentTableRow);
tabContentTable.appendChild(tabContentTableHead);
tabContentTable.setAttributeNode(styleAtt);
tabContentTable.setAttributeNode(classAtt);
tabContentTable.setAttributeNode(idAtt);
tabContentDiv.appendChild(tabContentTable);
document.getElementById("tabContent").appendChild(tabContentDiv);
console.log(tableID);
console.log(document.getElementById(tableID));
$("#"+tableID).DataTable({
"ajax": "https://beep1.free.beeceptor.com/MyMethod?number="+number
});