【问题标题】:Why aren't these two strings the same?为什么这两个字符串不一样?
【发布时间】:2015-03-26 01:49:51
【问题描述】:

我正在尝试编写一些 javascript 并使用 document.getElementById("ct100_ContentPlaceHolder1_search"); 获取一些元素,但由于某种原因它找不到它。它总是返回 null。

在反复思考这是我使用双引号或单引号后,我在文档中找到了元素的 id,并将该 id 打印到文本框。我将文本复制/粘贴到记事本,然后决定编写这段代码

var id = e.target.id;

if (id == "ctl00_ContentPlaceHolder1_search") {  <-- Copied/pasted from notepad. Returns true
    var foo6 = document.getElementById("ctl00_ContentPlaceHolder1_search");
}
if (id == "ct100_ContentPlaceHolder1_search") { <-- Typed out. Returns false
    var foo5 = document.getElementById("ct100_ContentPlaceHolder1_search");
}

页面是用 ASP.NET 构建的,如果这很重要的话。那么里面发生了什么?我没有头绪。

这是一个regexr,我用来显示两个字符串不一样。正则表达式是从记事本复制/粘贴的。说明‘1’不一样,那是什么‘1’呢?

【问题讨论】:

    标签: javascript asp.net ascii


    【解决方案1】:

    ctl 中的第一个字符串有一个小写 L。

    第二个在ct1 中有数字1。

    【讨论】:

    • 哇。好的。我什至没有注意到差异。
    猜你喜欢
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多