Код: Выделить всё
[list]
[*][url=~/]Home[/url]
[*][url=~/ListItem1]ListItem1[/url]
[*][url=~/ListItem2]ListItem1[/url]
Following items will be created Dynamically
@* [url=~/ListItem2/?param=SubItem1]SubItem1[/url]
[*][url=~/ListItem2/?param=SubItem2]SubItem2[/url]*@
[/list]
Added here for link testing:
[*][url=~/ListItem2/?param=SubItem1]SubItem1[/url]
[*][url=~/ListItem2/?param=SubItem2]SubItem2[/url]
< /code>
Все ссылки, которые написаны непосредственно в тегах HTML выше, работают нормально. < /p>
javascript: < /p>
var ExchangeLeftDropdown = document.getElementById("ListItemDropdown");
$(document).ready(function () {
var test = "Subitem1}SubItem2}"; //This string will be filled by a controller later on
var test2 = test.split("}");
for (i = 0; i < test2.length; i++) {
//Create List Item
var newListItem = document.createElement("li");
//Create Link Item
var itemLink = document.createElement("a");
//Add text to link Item
itemLink.textContent = test2[i];
//Add link URL to link Item
itemLink.setAttribute("href", "~/ListItem2/?dom=" + test2[i]);//Desired URL,
//but this tilde doesn't equate to home directory, so instead I get this
//in the URL http://localhost:1461/'DirectoryCurrentlyViewing'/~/ListItem2/?dom=SubItem2.
//it does lead to the right place if you navigate from the home directory
// itemLink.setAttribute("href", "");
// This attempt resulted in me getting a 404 error vs a Server Error in '/' Application
//The URl is again a directly pasted string: http://localhost:1461/ListItem2/
itemLink.setAttribute("runat", "server"); //The attempt to parse the URL server side didn't have any effect
newListItem.appendChild(itemLink);
ExchangeLeftDropdown.appendChild(newListItem);
}
});
Подробнее здесь: https://stackoverflow.com/questions/354 ... eated-link
Мобильная версия