gpt4 book ai didi

javascript - 使用 javascript 更新输入值

转载 作者:行者123 更新时间:2023-11-28 07:10:01 25 4
gpt4 key购买 nike

在我正在处理的页面上,有很多隐藏的输入:

<input a1="2" a2="1" a3="3" name="Value" type="hidden" value="10"> 
<input a1="4" a2="2" a3="6" name="Value" type="hidden" value="12">
<input a1="6" a2="3" a3="9" name="Value" type="hidden" value="14">
...

使用以下 JavaScript,我想更新某些输入的值:

<script type="text/javascript">
$('[name="value"]').on('input', function () {
$('[a1="' + $(this).attr('ds') + '"]').value = $(this).val();
});
</script>

但是我只想更新 a1 和 a2 都等于 $(this).val() 的输入的值

最佳答案

您只需要一个简单的测试来检查两者 a1 a2是否等于 $(this).val().

这是您需要的代码:

$('[name="value"]').on('input', function () {
if($(this).attr("a1") == $(this).val() && $(this).attr("a2") == $(this).val()){
$('[a1="' + $(this).attr('ds') + '"]').value = $(this).val();
}
});

关于javascript - 使用 javascript 更新输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31401421/

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