Использование Тильде (~) в динамически созданной ссылкеHtml

Программисты Html
Ответить
Anonymous
 Использование Тильде (~) в динамически созданной ссылке

Сообщение Anonymous »

Я создаю элементы подменю со ссылками и URL-адресами динамически с использованием JavaScript. Однако, когда я перемещаюсь по ссылкам, URL не анализирует ~ < /code> в качестве корневого каталога, но просто добавляет строку к текущему URL.

Код: Выделить всё





[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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Html»