我试图在Javascript中编写asp经典函数......但我似乎无法做到正确......有人能帮忙吗?
ASP:
Dim i
Dim sAscii
sAscii = ""
For i = 1 To Len(str)
sAscii = sAscii + "&#" + CStr(Asc(Mid(str, i, 1))) + ";"
Next
ascconv= sAscii
javascript:
var i;
str1 = document.getElementById('firstname').value;
var sAscii1;
i = 0;
sAscii1 = "";
for(i; i = str1.length; i++) {
sAscii1 = sAscii1 + "&#" + str1.charCodeAt(i) + ";";
}
document.getElementById('firstname').innerHTML = sAscii1;
答案 0 :(得分:1)
要在javascript中转换此功能,您必须执行以下操作:
var i,str1 = document.getElementById('firstname').value;
var sAscii1 = "";
for(var i=0; i < str1.length; i++) {
sAscii1 = sAscii1 + "&#" + str1.charCodeAt(i) + ";";
}
document.getElementById('firstname').value = sAscii1;//I think you made a mistake here...as you have a input variable you will get/set the value and not innerHTML
其中charCodeAt类似于Asc(转换为ascii代码)
答案 1 :(得分:0)
var i, sAscii = "", str = "This is a string";
for(i = 0; i < str.length; a++){
sAscii += "&#" + str[a].charCodeAt(0) + ";";
}