Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在页面上加载默认单选按钮_Javascript_Html_Checkbox - Fatal编程技术网

Javascript 在页面上加载默认单选按钮

Javascript 在页面上加载默认单选按钮,javascript,html,checkbox,Javascript,Html,Checkbox,我在页面上有下面的复选框代码。我需要在页面加载时默认选中这两个选项。这将显示查询的结果。现在,当其中一个复选框未选中时,需要提交表单并显示不同的查询结果。即使我取消选中一个复选框,复选框也始终处于选中状态。有人能带我到这里吗?谢谢 <form action="abc.cfm?show=yes" method="post" name="myform"> <table align="center"><tr> <td>

我在页面上有下面的复选框代码。我需要在页面加载时默认选中这两个选项。这将显示查询的结果。现在,当其中一个复选框未选中时,需要提交表单并显示不同的查询结果。即使我取消选中一个复选框,复选框也始终处于选中状态。有人能带我到这里吗?谢谢

   <form action="abc.cfm?show=yes" method="post" name="myform">
      <table align="center"><tr>
      <td>
     <input type="checkbox" checked="checked" name="chkbox" id="chkbox1"> <font size="3+"><strong> Agreement      Only</strong> </font>
       &nbsp;&nbsp;<input type="hidden" name="chk" id="chk1">
        <input type="checkbox" checked="checked" name="chkbox" id="chkbox2"> <font size="3+"><strong>Active          Employees</strong> </font>
     &nbsp;&nbsp;<input type="hidden" name="chk" id="chk2">
    </td>
    <td>
      <input type="Submit" name="submitnow" value="View now">
     </td>
        </table>
      </form>

             <cfif isdefined("form.chk1")>
                  query 1
              <cfelseif isdefined("form.chk2")>
                  query 2
             </cfif>

仅协议
在职员工
问题1
问题2
您可以使用
存储并发送选中的值

“保存所选单选按钮状态”到底是什么意思

在表单发布到的页面中,通过检查post变量,您将知道选中了哪个复选框。如果您的想法是再次显示包含上述代码的页面,并选中“用户选择”复选框,则可以查看以下内容(jQuery 1.6+):


我没有测试这个,也许有语法错误的地方,但你明白了。您需要使用jQuery应用我的解决方案。

当您说需要保存所选单选按钮状态时,您的意思是什么?您需要服务器端还是客户端的状态?在客户端。。。
$("#chkboxId").prop('checked', true); //check the checkbox with id chkboxId.
$("#chkboxId").prop('checked', false); //uncheck it.
var states = [false, false, true];

function saveStates()
{
    var context = $("#chk1,#chk2,#chk3");
    $(context).each(function (index) {
        states[index] = $(context[index]).prop("checked");
    });
}