我试图从javascript中的db中选择一个值。如果select在javascript中,为什么这不起作用。
$(document).ready(function() {
var max_fields = <?php foreach ($results2 as $rss) { ?><?php echo $rss["qty"]; ?><?php } ?>; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 0; //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('<div><br><tr><td><label for="kind">Part Number / part Name</label> <label for="qty">Quatity (Pcs)</label><br><select name="kind[]" class="select1" required><option value="">Please Select</option><?php foreach ($results1 as $rs) { ?><option value="<?php echo $rs["part_number"]; ?>/<?php echo $rs["part_name"]; ?>"><?php echo $rs["part_number"]; ?> -- <?php echo $rs["part_name"]; ?></option><?php } ?></select> <input name="qty[]" value="" autocomplete="off" onkeypress="return isNumberKey(event)" required/></td></tr><tr></tr><a href="#" class="remove_field"> Hapus</a></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
}) });
这是隐藏的,如果在选择下拉列表之前
$(document).ready(function(){
$("select").change(function() {
$('select[name="kind[]"]').not(this).find("option[value="+ $(this).val() + "]").attr('hidden', true); }); });
我从这里学到了 Prevent selecting same value in three different dropdowns