我正在尝试从表单中的动态下拉列表中获取值,但我的代码不起作用。查看.php<div class="input_fields_wrap"> <input type="button" class="btn btn-info add_field_button" value="Tambah Cara Pengolahan" /> <br /><br /></div><div class="service-container" data-service= "<div class='form-group'> <select class='form-control' style='width:88%; display:inline-block; margin-right:10px;' name='cara_pengolahan[]' required> <option value=''>No Selected</option> <?php foreach($pengolahan as $row):?> <option value='<?php echo $row->id_pengolahan;?>'><?php echo $row->cara_pengolahan;?></option> <?php endforeach;?>></div> </select> <button class='btn btn-danger closebtn remove_field'><b>×</b></button> </div>"</div>Javascript.js$('.service-container').each(function() { var container = $(this); var service = container.data('service'); // Service variable now contains the value of html + php variable; var max_fields = 10; //maximum input boxes allowed var wrapper = $(".input_fields_wrap"); //Fields wrapper var add_button = $(".add_field_button"); //Add button ID var x = 1; //initlal text box count $(add_button).click(function(e){ //on add input button click e.preventDefault(); if(x < max_fields){ //max input box allowed x++; //text box increment $(wrapper).append(service); } }); $(wrapper).on("click",".remove_field", function(e){ //user click on remove text e.preventDefault(); $(this).parent('div').remove(); x--; })});var cara_pengolahan = document.forms[0].elements["cara_pengolahan[]"];if(typeof cara_pengolahan !== 'undefined'){ for (var i=0; i<cara_pengolahan.length; i++) { console.log(cara_pengolahan[i].value); }}当有一个动态下拉列表时,返回它的所有数组值。但我想要的是捕获该下拉列表的选定值。并且当有多个动态下拉列表时,它会返回该下拉列表的正确选择值。如何捕获所有动态下拉列表的选定值?提前致谢。
添加回答
举报
0/150
提交
取消