我不确定这是CodeIgniter问题还是Javascript问题。

这是我的Javascript:

<script type="text/javascript">
function con(message) {
 var answer = confirm(message);
 if (answer) {
  return true;
 }

 return false;
}
</script>


这是我的CI:

echo form_submit('submit', 'Login', 'onclick="return con("Are you sure you don\'t have a configuration to submit? Please check the checkbox if you do.")');


为什么我没有收到确认对话框?我认为JS。 CI正确呈现了提交按钮。

最佳答案

您需要在JS中使用单引号:

                    // this double quote is causing issues with the onclick assignment.
onclick="return con("Are you sure you don\'t have a configuration to submit? Please check the checkbox if you do.")'


您甚至可以从SO看到颜色语法突出显示的问题

我建议:

onclick="return con(\'Are you sure you don\\'t have a configuration to submit? Please check the checkbox if you do.\')"'

关于javascript - JavaScript确认和CodeIgniter,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4749988/

10-13 00:35