开发者

How correctly assign value to field

开发者 https://www.devze.com 2023-01-03 11:55 出处:网络
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 &

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

&lt; corresponds <
&gt; corresponds >

the code would look like this

    function loadShareBox(pageTitle) {
        document.getElementById("shareHTML").value = '&lt;a href="' + document.location.href + '" target=_blank&gt;' + pageTitle + '&lt;/a&gt;';
    }

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号