[英]Drop Down to Set Initialize Value using Jquery
我尝试使用下拉菜单在所有字段上设置默认值。 例如: Let consider Drop down there is of three options like theme1, theme2 and theme
3,我有5 input fields.
在five input fields
具有适当的id
。
如果我选择theme1
它将值初始化为适当的5
输入字段。(我不确定是否可以将值分配给数组)
主题1继续
input1 => "hi";
input2 => "how";
input3 =>"are";
input4 =>"you";
如果我在下拉列表中选择theme1,则添加我在array中定义的值(如果可行)Theme2 contatin
input1 => "glad";
input2 => "to";
input3 =>"meet";
input4 =>"you";
如果我选择theme2
它将值初始化为适当的5
输入字段。(此值与theme1不同)
$('select').on('change', function() {
$("select option:selected").each(function () {
$('#price').val('$' + $(this).attr('value'));
});
});
现在我很有价值。 但是有一种方法可以调用该函数,而不是有人可以吗?建议我使用数组将一组初始化值设置为一个选项(theme1)。 这是我的小提琴
尝试这个
$('select').on('change', function () {
var data = $(this).val().split(' ');
var i = 0;
$('input').each(function () {
$(this).val(data[i]);
i++;
});
});
<select>
<option>Select an item</option>
<option value="Hello how are you">Item 1</option>
<option value="Glad to meet you">Item 2</option>
<option value="3">Item 3</option>
</select>
<input type="text" id="price">
<input type="text" id="another_price">
<input type="text">
<input type="text">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.