How correctly assign value to field
I am trying to assign value for one edit field(not asp.net control) in asp.net application using JavaScript code. It seems that < character in value string gives problems for ASP.NET. If I remove < and > characters from value everything works fine.
Where is the problem? How to pass <> characters to the field? I don't want to use ServerSide code I want to do it on ClientSide using JS and HTML Edit box.
function loadShareBox(pageTitle) {
document.getElementById("shareHTML").value = '&开发者_高级运维lt;a href="' + document.location.href + '" target=_blank>' + pageTitle + '</a>';
}
regards, Tomas
try using these
< corresponds <
> corresponds >
the code would look like this
function loadShareBox(pageTitle) {
document.getElementById("shareHTML").value = '<a href="' + document.location.href + '" target=_blank>' + pageTitle + '</a>';
}
edit: ah, I think there is another problem. You are trying to insert a new element within another element. So you should create a new element and append in shareHTML.
var myLink = document.createElement("a");
myLink.setAttribute("href", "mylink");
var text = document.createTextNode("Link name");
myLink.appendChild(text);
var myElement = document.getElementById("shareHTML")
myElement.appendChild(myLink);
this should do the work
精彩评论