Javascript 离子菜单动态不预先定义我可以使他们在选择时可见,这将适合您的情况。将重写这个。这是我将在django模板中使用的。在那里,我不知道我必须使用的选择字段的编号。这取决于数据库。这就是为什么我需要动态选择字段。我想你明白我的意思了,我为这个添加了一个JSFID
Javascript 离子菜单动态不预先定义我可以使他们在选择时可见,这将适合您的情况。将重写这个。这是我将在django模板中使用的。在那里,我不知道我必须使用的选择字段的编号。这取决于数据库。这就是为什么我需要动态选择字段。我想你明白我的意思了,我为这个添加了一个JSFID,javascript,jquery,html,Javascript,Jquery,Html,离子菜单动态不预先定义我可以使他们在选择时可见,这将适合您的情况。将重写这个。这是我将在django模板中使用的。在那里,我不知道我必须使用的选择字段的编号。这取决于数据库。这就是为什么我需要动态选择字段。我想你明白我的意思了,我为这个添加了一个JSFIDLE。只要它不是一个真正大的选择集,您就可以使用这种方法根据数据库内容很好地构造。有时这种结构可以由10、15个选择菜单组成。你还能推荐这种方法吗?谢谢你的回答。但这不是我要找的。不需要动态添加选择菜单,不需要预先定义。我可以在选择时显示它们,
离子菜单动态不预先定义我可以使他们在选择时可见,这将适合您的情况。将重写这个。这是我将在django模板中使用的。在那里,我不知道我必须使用的选择字段的编号。这取决于数据库。这就是为什么我需要动态选择字段。我想你明白我的意思了,我为这个添加了一个JSFIDLE。只要它不是一个真正大的选择集,您就可以使用这种方法根据数据库内容很好地构造
。有时这种结构可以由10、15个选择菜单组成。你还能推荐这种方法吗?谢谢你的回答。但这不是我要找的。不需要动态添加选择菜单,不需要预先定义。我可以在选择时显示它们,这将适合您的情况。将重写这个。这是我将在django模板中使用的。在那里,我不知道我必须使用的选择字段的编号。这取决于数据库。这就是为什么我需要动态选择字段。我想你明白我的意思了,我为这个添加了一个JSFIDLE。只要它不是一个真正大的选择集,您就可以使用这种方法根据数据库内容很好地构造
。有时这种结构可以由10、15个选择菜单组成。你还能推荐这种方法吗?
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
jQuery(function ($) {
$('.target').change(function () {
$("select option:selected").each(function () {
$('#other').append('<select class="target"><option value="3" selected="selected">option1</option><option value="4" selected="selected">option2</option> </select>');
});
});
});
</script>
</head>
<body>
<form>
<input class="target" type="text" value="Field 1" />
<select class="target">
<option value="1" selected="selected">Option 1</option>
<option value="2">Option 2</option>
</select>
</form>
<div id="other"></div>
</body>
</html>
$(document).on('change','.target',function() {
$("select option:selected").each(function () {
$('#other').append('<select class="target"><option value="3" selected="selected">option1</option><option value="4" selected="selected">option2</option> </select>');
});
});
$(document).on('change', '.target', function () {
$(this).after($(this).clone());
});
$(document).on('change', '.target', function () {
if ($(this).is($('.target:last'))) {
$(this).after($(this).clone());
}
});
$(document).on('change', '.target', function () {
if ($(this).is($('.target:last'))) {
var clone = $(this).clone();
clone.children('option').each(function () {
$(this).val(+($(this).val()) + 2);
});
$(this).after(clone);
}
});
$(function() {
var selector = {
first_select : '#second_select',
second_select : '#third_select'
}
$('#first_select, #second_select').bind('change', function() {
var h = $(this).val();
if (h) {
$(selector[$(this).attr('id')]).find('> optgroup').each(function() {
$(this).toggle(h == $(this).data('select-value'))
.attr('disabled', (h != $(this).data('select-value')));
});
$(selector[$(this).attr('id')]).find('option:visible').eq(0).attr('selected', true);
$(selector[$(this).attr('id')]).show();
}
});
});
<select id="first_select">
<option value="">Pick</option>
<option value="1">One</option>
</select>
<select id="second_select">
<optgroup data-select-value="1">
<option value="1_1">Choises appeares</option>
<option value="1_2">More choises</option>
</optgroup>
</select>
<select id="third_select">
<optgroup data-select-value="1_1">
<option value="1_1_1">Trippin' choises</option>
<option value="1_1_2">So many choises</option>
</optgroup>
<optgroup data-select-value="1_2">
<option value="1_2_1">Choises!!</option>
<option value="1_2_2">God, they're everywhere!</option>
</optgroup>
</select>
<style type="text/css">
#second_select,
#third_select {
display: none;
}
</style>