gpt4 book ai didi

javascript - jquery,从名称标签中提取数字值

转载 作者:行者123 更新时间:2023-11-29 09:59:29 25 4
gpt4 key购买 nike

这是我的 perl 脚本创建的。

    print qq|
\$('textarea[name=category$row[0]]').keydown(function(event)
{
\$("input[value=$row[0]]").attr('checked', true);
});
|;

稍后,我有了这个,我想重新提取 $row[0] 值,但我不确定如何在 jquery 中提取。

print qq|
<script>
\$('#display_category').change(function() {
var text = \$(this).val();

\$('textarea[name^="category"]').each(function() {
var foundvalue = \$(this).val();

if (text == foundvalue)
{
alert("FOUND HERE " + foundvalue);

}
});
});
</script>

|;

我如何从类别中重新提取\d+ 并在我的 if 条件中使用它?

最佳答案

alert("category1234".match(/\d+/g)[0]);

所以像这样:

var num = $(this).attr('name').match(/\d+/g)[0];

或者(我更喜欢这个):

var num = $(this).attr('name').replace(/[^\d]/g, '');

演示:http://jsfiddle.net/karim79/8r8vs/3/

关于javascript - jquery,从名称标签中提取数字值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4399368/

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