Ris*_*ker 0 html javascript css jquery select
我有这个js运作良好:
$(document).ready(function(){
$("select").change(function () {
var str = "";
str = $(this).find(":selected").text();
$(".out").text(str);
}).trigger('change');
Run Code Online (Sandbox Code Playgroud)
问题是如果我有多个选择下拉(假设没有限制)我必须将类更改为另一个所以它不会做同样的...意味着复制jquery ...有没有办法将它合并为一个?这是小提琴,看看我的意思:
使用.next()
$(document).ready(function () {
$("select").change(function () {
var str = "";
str = $(this).find(":selected").text();
$(this).next(".out").text(str);
// find the next element with class out element
}).trigger('change');
})
Run Code Online (Sandbox Code Playgroud)