将location.href放在带有innerHTML的变量中

时间:2017-04-11 11:07:14

标签: javascript html

我已将location.href的值放在一个变量中,并且我希望将该变量绑定在一个buuton的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},我使用alert函数测试函数的参数并且它可以工作,所以我确定问题在边界内,所以你可以告诉我什么地方出了错 谢谢

1 个答案:

答案 0 :(得分:1)

我认为这里错误onclick='location.href='"

应为onclick='location.href=\""+ goToConsulter +"\"'