如何使用firebug进行调试并显示单选按钮的值

我有单选按钮,如下所示。





我正在进行动态选择。 我有我的javascript代码发布值。 似乎供应商价值现已公布。 下面是我的脚本的代码。

  $(document).ready(function(){ function populate() { fetch.doPost('getSupplier.php'); } $('#lensType').change(populate); var fetch = function() { var counties = $('#county'); return { doPost: function(src) { $('#loading_county_drop_down').show(); // Show the Loading... $('#county_drop_down').hide(); // Hide the drop down $('#no_county_drop_down').hide(); // Hide the "no counties" message (if it's the case) if (src) $.post(src, { supplier: $('#lensType').val() }, this.getSupplier); else throw new Error('No source was passed !'); }, getSupplier: function(results) { if (!results) return; counties.html(results); $('#loading_county_drop_down').hide(); // Hide the Loading... $('#county_drop_down').show(); // Show the drop down } } }(); populate(); }); 

PHP代码:

 prepare("SELECT DISTINCT SupplierBrand FROM plastic WHERE HeadingNo='".$_POST['supplier']."'"); $stmt->execute(); $stmt->bind_result($supplierBrand); while ($row = $stmt->fetch()) : ?> <option value="" width="100px"> 

我的问题是当我调试时,我注意到没有传递给php脚本的值,这使得select为空。 我试图通过让firebug输出console.log进行跟踪或调试,但在这方面失败了。 请协助使用此代码,该代码旨在通过单选按钮选择显示动态列表。

在你的javascript中,你得到的是div的值,而不是单选按钮:

 $('#lensType').val() <--- change that 

对于这样的事情:

 $("#lensType input:radio[name='design']:checked").val() 

用于调试:

 $('input[name="design"]').change(function(){ console.log($('#lensType').find("input:radio[name ='design']:checked").val()); }); 

其他:

 $('#lensType').find("input:radio[name ='design']:checked").val(); 

代替

 $('#lensType').val() 

你可能想要用改变的函数包装它,因为onload没有选择设计:

  $(document).ready(function(){ $('input[name="design"]').change(function(){ var design = $('input[name="design"]:checked').val(); function populate() { fetch.doPost('getSupplier.php'); } $('#lensType').change(populate); var fetch = function() { var counties = $('#county'); return { doPost: function(src) { $('#loading_county_drop_down').show(); // Show the Loading... $('#county_drop_down').hide(); // Hide the drop down $('#no_county_drop_down').hide(); // Hide the "no counties" message (if it's the case) if (src) $.post(src, { supplier: design }, this.getSupplier); else throw new Error('No source was passed !'); }, getSupplier: function(results) { if (!results) return; counties.html(results); $('#loading_county_drop_down').hide(); // Hide the Loading... $('#county_drop_down').show(); // Show the drop down } } }(); populate(); }); });