jQuery选择具有动态ID的选项列表 [英] jquery select the option list with dynamic id

查看:81
本文介绍了jQuery选择具有动态ID的选项列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选项列表,其ID有时可能是其中之一:

I have an option list with an id that could sometimes be one of these:

edit-panes-billing-billing-zone
edit-panes-billing-billing-zone--1
edit-panes-billing-billing-zone--2
edit-panes-billing-billing-zone--3
edit-panes-billing-billing-zone--4

一次只有一个选择元素.

There is only one select element at a time.

是否可以使用jQuery动态选择选项列表?
这是我尝试过的,但是没有用:

Is it possible to select the option list dynamically with jQuery?
This is what I've tried, but it's not working:

$("select[id^='edit-panes-billing-billing-zone--']").each(function() {
    alert('test'):              
}

推荐答案

您的代码中存在许多失败的语法错误:

You have a number of failing syntax errors in your code:

alert('test'):  

应该是

alert('test');  

还有

alert('test'):              
}

应该是

alert('test');              
});

最终结果应该是:

$("select[id^='edit-panes-billing-billing-zone--']").each(function() {
    alert('test');             
});

这在我运行的所有测试中均成功.

This succeeds in all the tests I've run.

这篇关于jQuery选择具有动态ID的选项列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆