×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

What's the difference between the following codes?(asp)

Code1:
<%
empid=Server.URLEncode("你好")
%>
<a href="javascript:newURL('EqpHist.asp?empid=<%=Server.URLEncode(empid)%>')">a link</a>

Code2:
<%
empid=Server.URLEncode("你好")
%>
<a href="#" onclick="newURL('EqpHist.asp?empid=<%=Server.URLEncode(empid)%>')">a link</a>

In both case,newURL is a javascript function

function newURL(URL)
{
var change = document.MainForm.hidChange.value
if (change == "TRUE") {
response = window.confirm("<%=msg%>")
if (response == false)
return
}
window.location.href = URL
}
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / What's the difference between the following codes?(asp)
    Code1:
    <%
    empid=Server.URLEncode("你好")
    %>
    <a href="javascript:newURL('EqpHist.asp?empid=<%=Server.URLEncode(empid)%>')">a link</a>

    Code2:
    <%
    empid=Server.URLEncode("你好")
    %>
    <a href="#" onclick="newURL('EqpHist.asp?empid=<%=Server.URLEncode(empid)%>')">a link</a>

    In both case,newURL is a javascript function

    function newURL(URL)
    {
    var change = document.MainForm.hidChange.value
    if (change == "TRUE") {
    response = window.confirm("<%=msg%>")
    if (response == false)
    return
    }
    window.location.href = URL
    }
    • Code 1 is using javascript protocol, code 2 is using DHTML.
    • 个人觉得, 如果是写程序就选2, 如果是面试问题就说两者没区别.
    • 我在IE6和IE7里测试的结果:code1把"你好"变成了乱码.code2可以正确完成参数的传递. Firefox里面两个都正确. 哪位大侠知道其中的道理吗?