gpt4 book ai didi

javascript - 更多 div 中的 DOM 元素的 jquery 更改属性?

转载 作者:行者123 更新时间:2023-11-30 16:36:32 26 4
gpt4 key购买 nike

假设我必须在几个 div 中更改表单的操作:

<div class="div1" id="contact">
<div class="div2">
<div class="div3">
<form class="contactform" action="" method="post">
<button type="submit"></button>
</form>
</div>
</div>
</div>

如何使用 jQuery 更改 form with class="contact form"action 属性?

最佳答案

如果您只有页面中的表单,那么您可以直接使用所有 css 选择器更改属性,例如:

$('form').attr('action', 'theupdatedaction');

其中 $('form') 是标签名称选择器,它选择页面上所有可用的 form。这可以更改为 #id 选择器和 . 类选择器:

 $('.contactform') // for class selector
$('#contactform') // for ID selector

甚至您可以从父元素使用 .find():

$('#contact').find('.contactform').attr('action', 'theupdatedaction');

关于javascript - 更多 div 中的 DOM 元素的 jquery 更改属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32630776/

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