【发布时间】:2011-02-08 17:49:26
【问题描述】:
我有一个 jQuery 函数,它查找嵌套在 ID 为 #popupForm 的容器 DIV 中的所有图像,查看 SRC 属性并将其与隐藏输入进行比较,该隐藏输入的值由服务器端变量创建。一旦渲染,如果有匹配,它将在图像的 SRC 上进行替换,hense:
var thisTheme = $("#hiddenTheme").val();
var defaultTheme = "/midway/firstTheme/"
$('#popupForm img').each(function () {
var thisSRC = $(this).attr('src');
if (thisSRC.indexOf(defaultTheme) !== -1) {
var new_src = $(this).attr('src').replace(defaultTheme, thisTheme);
$(this).attr('src', new_src);
}
});
现在这很好用,但我希望扩展此代码的循环部分(.each 部分),因此它不仅查看容器 DIV 中的图像,而且查看所有输入(是的,某些输入具有 SRC 属性 -请不要问为什么)
我正在考虑添加这样的数组
var arrValues = ["#popupForm img", "#popupForm input"];
然后改变每个选择器部分来包含数组,像这样
$(arrValues).each(function () {
有谁知道我修改代码的最佳方法,到目前为止我尝试过的方法没有奏效!
谢谢
【问题讨论】:
-
嗨,迈克,我想我在这次谈话中为时已晚,但你得到答案了吗?
标签: jquery