我不确定这是一个CodeIgniter问题还是一个Javascript问题。
这是我的Javascript:
<script type="text/javascript">
function con(message) {
var answer = confirm(message);
if (answer) {
return true;
}
return false;
}
</script>这是我的个人资料:
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会正确地呈现submit按钮。
发布于 2011-01-21 01:00:41
您需要在您的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.\')"'发布于 2011-01-21 00:51:23
这段代码将进入无限循环,因为您将函数命名为与内置JavaScript confirm相同的confirm。
因此,在您的confirm函数中,当它调用confirm时,它将调用您的函数,而不是本机函数。
本机JavaScript confirm函数返回true或false,因此不需要您的方法。
编辑:问题出在你调用form_submit的时候。
更改:
'onclick="return con("Are you sure you don\'t have a configuration to submit? Please check the checkbox if you do.")'至:
'onclick="return con(\'Are you sure you don\\\'t have a configuration to submit? Please check the checkbox if you do.\')"'发布于 2011-01-21 00:48:22
你的代码不是进入了无休止的循环吗?
您已经重新定义了confirm() JS函数,并且正在递归地执行您的函数。
https://stackoverflow.com/questions/4749988
复制相似问题