如何显示“所选择的单选按钮”刷新后? [英] How to display "selected radio button" after refresh?
问题描述
刷新页面后,用户选择的单选按钮丢失。
即使我刷新了页面,我如何能始终显示用户的选择的单选按钮?
< input name =radiobuttontype =radiovalue =id =allchecked />
选中的收音机不合适,因为它将始终显示默认的单选按钮。
以下是我的代码: -
< form name =myfrmid =myfrmaction =method =post>
< input name =radiobuttontype =radiovalue =id =all/>
< label>所有语言< / label>
< input name =radiobuttontype =radiovalue =id =english/>
< label>英文< / label>
< / form>
您应该符合标准,并为每个属性。这意味着你需要check =checked
< input name =radiobuttontype =radiovalue = id =allchecked =checked/>
如果您在问如何坚持以前选择的内容:AFAIK,这是不可能的使用纯HTML。您需要将提交所选单选按钮的JavaScript事件绑定到您的服务器,并将动态生成的页面(通过PHP,Python,无论如何)将checked =选中添加到已检查的单选按钮。 p>
编辑:
如我所见,将当前选中的单选按钮提交到服务器和动态生成您的页面可能会过度。
After refresh the page, the user selected radio button is missing. How can i always display the user's "selected radio button" even I had refresh the page?
<input name="radiobutton" type="radio" value="" id="all" checked />
radio with checked is not suitable, because it will always display the default radio button.
Below is my code:-
<form name="myfrm" id="myfrm" action="" method="post">
<input name="radiobutton" type="radio" value="" id="all" />
<label>All Languages</label>
<input name="radiobutton" type="radio" value="" id="english" />
<label>English</label>
</form>
You should conform to standards and give a value to every attribute. That means you need checked="checked"
<input name="radiobutton" type="radio" value="" id="all" checked="checked" />
And in case you were asking how to stick to what was selected previously: AFAIK, it is not possible with plain HTML. You need to bind a Javascript event that submits the selected radio button to your server and a dynamically generated page (by PHP, Python, whatever) that puts the 'checked="checked" to the radio button that was submitted as checked.
EDIT:
As I see it, submitting the currently selected radio button to the server and generating your page dynamically might be overkill.
这篇关于如何显示“所选择的单选按钮”刷新后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!