【问题标题】:put location.href in a variable with innerHTML将 location.href 放入带有 innerHTML 的变量中
【发布时间】:2017-04-11 11:07:13
【问题描述】:

我已将 location.href 的值放入一个变量中,我想将该变量绑定到一个按钮的 onclick 中,我将它添加到带有 inner.html 的 div 上

这是我的代码:

  function absence(id)
          { 
                var goToConsulter ="<?php echo site_url('index.php/Enseignant/consulter_presence/'); ?>"+id;

             document.getElementById(id).innerHTML = "<button class='btn btn-primary' onclick='location.href='"+ goToConsulter +"'> Consulter</button><button class='btn btn-primary' onclick='marquer("+id+")'>Marquer</button>";  

          }

但它显示一个错误:Uncaught SyntaxError: Unexpected token },我用警报函数测试了函数的参数,它可以工作,所以我确定问题在一定范围内,所以你能告诉我发生了什么吗错误的 谢谢

【问题讨论】:

  • &lt;?php echo site_url('index.php/Enseignant/consulter_presence/'); ?&gt;输出了什么?

标签: javascript html


【解决方案1】:

我觉得这里应该是错的onclick='location.href='"

应该是onclick='location.href=\""+ goToConsulter +"\"'

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 2017-07-04
    • 1970-01-01
    • 2020-02-24
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 1970-01-01
    • 2016-08-22
    相关资源
    最近更新 更多