如何将child的name属性添加到parent

时间:2013-08-12 08:02:05

标签: jquery forms radio-button

我是一个新手,我正在尝试创建自定义收音机盒,父母会收到孩子的名字和选定的值属性,然后从父母的孩子那里删除name属性。

$(".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

});

我一直试图让父母接受孩子的姓名属性。 这就是我所拥有的:http://jsfiddle.net/Jdpsv/

提前致谢!

1 个答案:

答案 0 :(得分:0)

您无法向value添加div属性,而是可以使用data-value

$(this).parent().data("value", $(this).attr("value"));

或者您希望的任何其他绰号,只要HTML标记为data-moniker并且您通过.data('moniker')访问