自动提交单选按钮,但保持选中状态

Auto-submit a radio button but keep it selected(自动提交单选按钮,但保持选中状态)
本文介绍了自动提交单选按钮,但保持选中状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用单选按钮对分页结果进行排序.但是,只要单击并自动提交该按钮,它就会变为未选中状态.我想保持按钮被选中,以便用户知道他们选择了哪个按钮.我该怎么做?

I am using radio buttons to sort through paginated results. However, whenever the button is clicked and auto-submitted, it becomes unselected. I want to keep the button selected so that the user knows which one they selected. How can I do that?

这是我所拥有的:

function autoSubmit() {
    var formObject = document.forms['theForm'];
    formObject.submit();
}

<input type="radio" name="sort" value="time" onChange="autoSubmit();" />
<input type="radio" name="sort" value="year" onChange="autoSubmit();" />
<input type="radio" name="sort" value="name" onChange="autoSubmit();" />

if(isset($_GET["sort"])) { 
    $sort = $_GET["sort"];
}

推荐答案

我猜你的代码是这样的:

I presume that your code is something like this:

<?php
$sort = "";
if(isset($_GET["sort"]))
{ $sort = $_GET["sort"]; }
?>
<html>
<head>
<script>
function autoSubmit()
{
    var formObject = document.forms['theForm'];
    formObject.submit();
}
</script>
</head>
<body>
<form name='theForm' id='theForm'>
    <input type="radio" name="sort" <?php if ($sort == 'upload_time') { ?>checked='checked' <?php } ?>value="upload_time" onChange="autoSubmit();" />Recently Uploaded
    <input type="radio" name="sort" <?php if ($sort == 'article') { ?>checked='checked' <?php } ?> value="article" onChange="autoSubmit();" /> Alphabetically
    <input type="radio" name="sort" <?php if ($sort == 'year') { ?>checked='checked' <?php } ?> value="year" onChange="autoSubmit();" /> Most Recent
</form>
</body>
</html>

这篇关于自动提交单选按钮,但保持选中状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)