ajax 调用复选框 Internet Explorer
我在使用 Internet Explorer 和 Ajax 时遇到了这个小问题。 所以首先我只使用了 php,一切都工作了,但是因为我不想重新加载页面,所以我使用了 ajax。
所以我有一个带有复选框的表单。当有人单击该复选框时,我的 ajaex 会被调用,并且数据库中的输入会发生更改。在 Firefox 中没有问题,但在 Internet Explorer 中不起作用。
这是我的代码的一部分:
<script language="javascript" type="text/javascript">
function changefield($doss, $display){
$.get("update.php",{dossier: $doss, CSQ_DISPLAY:$display});
alert("test");
}
</script>
echo '<form id="'.$r ['BC_DOSSIER'].'" method="get" action="">
<input type="checkbox" name="CSQ_DISPLAY" '.$checked .' onchange="changefield(\''.$r ['BC_DOSSIER'].'\',this.checked)">
</form>';
似乎在资源管理器中,我仅在选中复选框时才会收到警报。 (问题是因为它首先读取数据库是否必须检查,因此您可以稍后更改它)。
有人知道我哪里错了吗?
预先非常感谢您的答复。
I'm having this little problem with internet explorer and ajax.
So first I used just php, and everything, worked, but because I don't want to reload the page, I use ajax.
So I have a form with a checkbox. When someone clicks on the checkbox, my ajaex is called and the input is changed in the db. In firefox there is no problem, but It doesn't work in internet explorer.
Here's a part of my code:
<script language="javascript" type="text/javascript">
function changefield($doss, $display){
$.get("update.php",{dossier: $doss, CSQ_DISPLAY:$display});
alert("test");
}
</script>
echo '<form id="'.$r ['BC_DOSSIER'].'" method="get" action="">
<input type="checkbox" name="CSQ_DISPLAY" '.$checked .' onchange="changefield(\''.$r ['BC_DOSSIER'].'\',this.checked)">
</form>';
It seems that in explorer, I only get the alert when the checkbox was checked. (Problem because it first reads the db if it must be checked or not, so you can change it later).
Does someone know where I went wrong?
Thank you very much in advance for the answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我更喜欢这样定义它,我讨厌在 HTML 中使用
onclick
:edit FIXED (注册为
change
而不是点击
)编辑 包裹在
$(document).ready()
编辑还添加了一个
click
事件这将将该处理程序注册到类名“ajax_check”的所有输入,而不会留下一个函数弄乱窗口对象,也不会弄乱你的 HTML。尝试一下,看看它是否解决了问题 - 它可能不是因为它基本上做同样的事情,但恕我直言,这是一种更好的方法。如果仍有问题,请回来找我,我们将进行调试。
请注意,使用这种方法时,
在 DOM 准备好之后执行非常重要,因此它应该在正文中的复选框之后定义,或者(更好)包裹在
$(window).load()
或(最好)$(document).ready()
内。I would prefer to define it like this, I hate using
onclick
in my HTML:edit FIXED (registered to
change
instead ofclick
)edit Wrapped in
$(document).ready()
edit Added a
click
event as wellThis will register that handler to all inputs with the className 'ajax_check', without leaving a function cluttering up the window object, and without messing up your HTML. Try it out and see if it fixes the problem - it may not as it does basically the same thing, but it's a better way of doing it IMHO. If you still have a problem, come back to me and we'll debug it.
Note that using this approach, it is important that the
<script>
is executed after the DOM is ready, so it should either be defined in the body after the checkbox or (better) wrapped inside$(window).load()
or (best)$(document).ready()
.在您的代码中,后备函数值不会传递给 IE。
即)在上面的代码中 onchange="changefield(\''.$r ['BC_DOSSIER'].'\',this.checked)" this.checked 对 IE 不起作用,所以你可以传递 this 并获取值在四个功能中,这适用于所有浏览器。例如)像这样
并获取函数内的选中属性。
我希望这会起作用。
In your code fallback function value wont passed for IE.
i.e) in above code onchange="changefield(\''.$r ['BC_DOSSIER'].'\',this.checked)" this.checked will not work for IE, so you can pass as this and get the value in four function, this will work for all the browsers. e.g) like this
and get the checked attribute inside the function.
I hope this will work.