gpt4 book ai didi

javascript - 在jquery中匹配2个特定的正则表达式

转载 作者:行者123 更新时间:2023-12-03 03:17:40 25 4
gpt4 key购买 nike

也许这个问题没有解决办法。

$("input[id^='pricechange']").on("input", function() {
if (this.value != $("input[id^='rate']")) {

}
});

我有一个在单元格中包含输入的表格,它是动态的并且可以有任意数量的行。我使用正则表达式来获取字段的任何更改:pricechange123pricechange000pricechange999 等。一旦用户输入值,它就会需要将其与费率列中的随附值交叉引用:rate123rate000rate999。截至目前 $("input[id^='rate']") 将获取所有费率。

有没有办法知道哪个 id 被选取了?

最佳答案

在该输入处理程序中,它只是 this.id

$("input[id^='pricechange']").on("input", function() {
console.log(this.id);

// extract the numeric part:
var myIdNumber = this.id.replace('pricechange', '');
// so you can use it on the #rate123 element similarly:
if (this.value != $('#rate' + myIdNumber).value) {
// ...
}

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="pricechange1">
<input id="pricechange2">

关于javascript - 在jquery中匹配2个特定的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46696020/

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