0

我有一个表格:

Check this if you Want to receive our newsletter: <input type="checkbox" id="newsletter " name="newsletter">

我通过 javascript/jquery 函数提交它。

在 js 文件中,在提交函数中,我得到了值:

var newsletter = $("#newsletter").val(); 

其余的 fom 值与 $.ajax 一起通过 POST 发送到我的 php 文件。

问题是:时事通讯的价值始终处于“开启”状态。

如果选中复选框,如何获取一个值,如果未选中,如何获取另一个值?

非常感谢!!

4

1 回答 1

0

要探测复选框是打开还是关闭,请使用.attr('checked')

var newsletter = $("#newsletter").attr('checked') ? "on" : "off";

这会给你'on'检查和'off'未检查。

于 2012-06-14T14:57:11.770 回答