【问题标题】:How to add child's name attribute to parent如何将孩子的姓名属性添加到父母
【发布时间】:2013-08-12 08:02:04
【问题描述】:

我是新手,我正在尝试创建自定义单选框,父母可以在其中接收孩子的姓名和选定的值属性,然后从父母的孩子中删除名称属性。

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

提前致谢!

【问题讨论】:

  • 向上收音机和向下收音机之间有链接吗?当他们谈论父母和孩子时,他们谈论的是文档中的嵌套元素。您的收音机列表位于单独的 div 中。它们之间没有链接。

标签: jquery forms radio-button


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2020-10-05
    • 2020-01-27
    • 1970-01-01
    • 1970-01-01
    • 2013-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-06
    相关资源
    最近更新 更多