从内联的javascript启动单选按钮名称 [英] Initiate the radio button name from javascript in inline
本文介绍了从内联的javascript启动单选按钮名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在内联html中从javascript变量中分配单选按钮值。因为我有很多单选按钮,我有一个情况是在localstorage中保存单选按钮名称,所以我需要给单选按钮名称唯一。如果我手动更改每个单选按钮名称,则需要更多时间。 />
我试过了
< < span class =code-leadattribute> script >
var sampe == XXID;
< / script >
< 输入 类型 = radio name =' javascript:sample+ n1' / >
我打算在每个html页面上使用唯一名称。
解决方案
当您想让用户从一组备选项中仅选择一个选项时,使用单选按钮。为此,相关的单选按钮必须具有相同的名称才能将它们标识为一个组。例如
< 表格 >
< 输入 < span class =code-attribute> type = radio name = 性别 value = 男性 已选中 > 男性
< br >
< <跨越ss =code-leadattribute>输入 type = radio name = 性别 < span class =code-attribute> value = female > 女性
< / form < span class =code-keyword>>
如果您想以编程方式将名称属性分配给单选按钮组,请尝试以下操作:< !DOCTYPE html >
< html >
< head >
< script src = http://ajax.googleapis.com/ajax/ libs / jquery / 1.11.2 / jquery.min.js > < / script >
< script >
(document).ready(函数(){
。( 输入:无线电)ATTR( 姓名, 性别);
});
< / script >
< / head >
< body > ;
< 表格 >
< 输入 类型 = radio value < span class =code-keyword> = male 已选中 > 男性
< br >
< 输入 type = radio value = female > 女性
< / form >
< / body >
< / html >
I want to assign the radio button value from javascript variable, in inline html. Because I have lot of radio button, and I have a situation to save the radio button name in localstorage, so should I need to give the radio button name unique.If I change every radio button name manually, it take more time.
I have tried
<script>
var sampe=="XXID";
</script>
<input type="radio" name='"javascript:sample"+n1'/>
I have plan to using unique name on the every html page.
解决方案
Radio buttons are used when you want to let the user select only ONE option from a set of alternatives. For this to work, related radio buttons must have the same name to identified them as a group. e.g.
<form> <input type="radio" name="gender" value="male" checked>Male <br> <input type="radio" name="gender" value="female">Female </form>
If you wan to assign name attribute to the radio button group programmatically, try this:<!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script>
(document).ready(function(){
("input:radio").attr("name","gender"); }); </script> </head> <body> <form> <input type="radio" value="male" checked>Male <br> <input type="radio" value="female">Female </form> </body> </html>
这篇关于从内联的javascript启动单选按钮名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文