gpt4 book ai didi

jquery - 替换 jQuery 中的部分表单元素属性

转载 作者:行者123 更新时间:2023-12-01 00:16:43 24 4
gpt4 key购买 nike

我想用新值替换部分名称属性。该值取决于原始值。 name 属性的值为:timeslots[timeslot_1][start]

  1. 如何将值“timeslot_1”增加到“timeslot_2”并用此值替换原始值?

  2. cloneElm 由两种类型的元素组成(输入和选择) - 我希望能够在循环中捕获这两种元素。

我到目前为止的代码:

$(cloneElm).children('span').children('input').each(function(id) {
var newName = $(this).attr('name').replace('timeslot_1', 'timeslot_2');
$(this).attr('name', newName);
});

谢谢

最佳答案

我认为 .attr() 这种更通用的方法这就是您所追求的:

$(cloneElm).find(':input').attr('name', function(i, name) {
return name.replace('timeslot_1', 'timeslot_2');
});

关于jquery - 替换 jQuery 中的部分表单元素属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4078299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com