gpt4 book ai didi

javascript - If 语句在 ie7 中不起作用

转载 作者:行者123 更新时间:2023-11-30 13:29:52 25 4
gpt4 key购买 nike

我正在研究 mousedown 函数,但出于某种原因,我的 if 语句在以下代码中的 ie7 中不起作用。适用于 ie8、Chrome 和 FF。

我做错了什么?

$("dd.office").mousedown(function() {
var btnTxt=$(this).text();
for (var i = 0; i < offices.length; i++) {
var teOffice = offices[i];
if (btnTxt==teOffice[0]){
alert("Why Doesnt this work in ie7?");
}
}
});

var offices = [
['Office1', -33.3, 151.426039, 2],
['Office2', -33.9, 151.18743, 3],
['Office3', -37.9, 145.156302, 1]
];

页面代码

<dl>
<dt>Info</dt>
<dd class="office" >Office1</dd>
<dd class="office" >Office2</dd>
<dd class="office" >Office3</dd>
</dl>

最佳答案

您的 btnTxt 有尾随空格 ()。

执行以下操作之一:

  1. btnTxt = $(this).text().replace(/\s$/,'')
  2. if (btnTxt.replace(/\s$/,'')==teOffice[0]){

关于javascript - If 语句在 ie7 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7142288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com