Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript多读/少读(+;/-)按钮在IE中不起作用_Javascript_Button_Cross Browser_Parameterized - Fatal编程技术网

JavaScript多读/少读(+;/-)按钮在IE中不起作用

JavaScript多读/少读(+;/-)按钮在IE中不起作用,javascript,button,cross-browser,parameterized,Javascript,Button,Cross Browser,Parameterized,下面的“阅读更多”文本扩展“+/-”按钮脚本在Chrome中运行,但在IE中不起作用。我可以看到一些线程说let现在应该在IE11中工作。有人能帮我纠正这个脚本,使其在两种浏览器中都能正常工作吗 提前谢谢 <table> <tr> <td class="definition" data-keyword="dog"> <button onclick="expandMore('dog')" cl

下面的“阅读更多”文本扩展“+/-”按钮脚本在Chrome中运行,但在IE中不起作用。我可以看到一些线程说let现在应该在IE11中工作。有人能帮我纠正这个脚本,使其在两种浏览器中都能正常工作吗

提前谢谢

    <table>
  <tr>

          <td class="definition" data-keyword="dog"> 
              <button onclick="expandMore('dog')" class="myBtn">+</button><strong>Definition of a dog</strong> a domesticated carnivorous mammal that typically has         
              <span class="threeDots"> ... </span>
              <span class="hiddenText" style="display: none;"><br>a long snout, an acute sense of smell, non-retractable claws, and a barking, howling, or whining voice.</span>              
          </td>
        <td>8 (3)(d)</td>
      </tr>

</table>

<script>
function expandMore(keyword) {
    let threeDots = document.querySelector(`.definition[data-keyword="${keyword}"] .threeDots`);
    let hiddenText = document.querySelector(`.definition[data-keyword="${keyword}"] .hiddenText`); 
    let btnText = document.querySelector(`.definition[data-keyword="${keyword}"] .myBtn`);

    if (threeDots.style.display === "none") {
        threeDots.style.display = "inline";
        btnText.textContent = "+";
        hiddenText.style.display = "none";
    } else {
        threeDots.style.display = "none";
        btnText.textContent = "-"; 
        hiddenText.style.display = "inline";
    }
}
</script>

+狗的定义一种家养食肉哺乳动物,通常有
... 

长鼻子、敏锐的嗅觉、不可伸缩的爪子和吠叫、嚎叫或呜咽的声音。 8(3)(d) 函数expandMore(关键字){ 设threeDots=document.querySelector(`.definition[data keyword=“${keyword}]].threeDots`); 让hiddenText=document.querySelector(`.definition[data keyword=“${keyword}]].hiddenText`); 设btnText=document.querySelector(`.definition[data-keyword=“${keyword}]].myBtn`); 如果(threeDots.style.display==“无”){ threeDots.style.display=“inline”; btnText.textContent=“+”; hiddenText.style.display=“无”; }否则{ threeDots.style.display=“无”; btnText.textContent=“-”; hiddenText.style.display=“inline”; } }
我认为IE还不支持模板文字。 如果您查看以下内容:

换成

let threeDots = document.querySelector('.definition[data-keyword="' + keyword + '"] .threeDots');

或者使用Babel传输它

谢谢@onecompileman,代码不起作用,但Babel的翻译起作用了:
var threeDots=document.querySelector(“.definition[data keyword=\”“.concat(keyword,\”].threeDots”);var hiddenText=document.querySelector(“.definition[data keyword=\”.concat(keyword,“\”].hiddenText”);var btnText=document.querySelector(“.definition[data关键字=\”.concat(关键字“\”].myBtn”)酷,我已经编辑了我的答案,我忘记了“+”这就是为什么它不工作的原因