Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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
Jquery 如何将子项的名称属性添加到父项_Jquery_Forms_Radio Button - Fatal编程技术网

Jquery 如何将子项的名称属性添加到父项

Jquery 如何将子项的名称属性添加到父项,jquery,forms,radio-button,Jquery,Forms,Radio Button,我是一个新手,我正在尝试创建自定义的单选框,其中父母接收他们孩子的名字和选定的值属性,然后从父母的孩子中删除名字属性 $(".radio").parent().addClass("radio-buttons"); //add styling $(".radio").parent().attr("name", $(this).next().attr("name")); // supposed to assign names to parents $(".radio").removeAttr("n

我是一个新手,我正在尝试创建自定义的单选框,其中父母接收他们孩子的名字和选定的值属性,然后从父母的孩子中删除名字属性

$(".radio").parent().addClass("radio-buttons"); //add styling
$(".radio").parent().attr("name", $(this).next().attr("name")); // supposed to assign names to parents

$(".radio").removeAttr("name"); //remove name after assignment to parent



$(".radio").click(function(){
    $(this).parent().find("a").css({
        background:"",  
        "box-shadow": ""
        }); //reset any previous selections

    $(this).parent().attr("value", $(this).attr("value")); //assign parent the selected value

    $(this).css({
        background:"#005fc3",
        "box-shadow": "2px 3px 5px #004793 inset"
    }); // Styling for selected state

});
我一直在努力让父母接受他们孩子的名字属性。 这就是我所拥有的:

提前谢谢

您不能向div添加value属性,而是可以使用data value


或者您想要的任何其他名字对象,只要HTML标记是数据名字对象,并且您可以通过.data'monike'访问它。

上行收音机和下行收音机之间有链接吗?当他们谈论父对象和子对象时,他们谈论文档中的嵌套元素。你的收音机列表是分开的。他们之间没有联系。
$(this).parent().data("value", $(this).attr("value"));