1
我在我的页面上有一个语言选择器选项的下拉菜单。在选择语言时,我希望我的标签和按钮html可以根据语言进行更改? 我的代码在更改语言时更改div的所有元素(html)?
var arr = [];
// gets all the ids starting with comp_
$('div[id^="comp_"]').each(function(){
arr.push(this.id);
labels = $(this).find('label');
buttons = $(this).find('button');
//get all labels inside the current div
$(labels,buttons).each(function(){
$(this).html("");
});
});
console.log(arr);
},
* 问题* 只reference.can我运行多个元素引用的函数改变标签元素的参考,而不是按钮?
它工作,如果我这样做,但我不想再重复相同的代码不同影响引用
var arr = [];
// gets all the ids starting with comp_
$('div[id^="comp_"]').each(function(){
arr.push(this.id);
labels = $(this).find('label');
buttons = $(this).find('button');
//get all labels inside the current div
$(labels).each(function(){
$(this).html("");
});
$(buttons).each(function(){
$(this).html("");
});
});
console.log(arr);
},
对......如果你能解释上面的代码是干什么的?它的作品只是想知道如何因为我可能需要添加更多的元素引用..感谢 – inputError
在编辑 – inputError
@ user2125700后得到它好吧我添加了一些更多的细节。 – Pointy