如何使用萤火虫进行调试并显示单选按钮的值 [英] How to debug using firebug and show the value of radio button

查看:157
本文介绍了如何使用萤火虫进行调试并显示单选按钮的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 < div id =lensType> 

< input type =radioname =designstyle =vertical-align:middlevalue =1/>
< label for =design> Single Vision< / label>< br />

< input type =radioname =designstyle =vertical-align:middlevalue =2/>
< label for =material>调节支持< / label>< br />

< input type =radioname =designstyle =vertical-align:middlevalue =3/>
< label for =design> Bifocal< / label> <峰; br />

< input type =radioname =designstyle =vertical-align:middlevalue =4/>
< label for =material> Varifocal(Intermediate / Near)< / label>< br />

< input type =radioname =designstyle =vertical-align:middlevalue =5/>
< label for =material> Varifocal(Distance / Near)< / label>

< / div>

我正在做一个动态选择。我有我的JavaScript代码发布的价值。现在看来供应商的价值已经发布了。下面是我的脚本的代码。

  $(document).ready(function(){

函数populate(){
fetch.doPost('getSupplier.php');
}

$('#lensType')。change(populate);

var fetch = function(){

var counties = $('#county');

return {
doPost:function(src ){
$ b $('#loading_county_drop_down')。show(); //显示Loading ...
$('#county_drop_down')。hide(); //隐藏(隐藏)隐藏无县消息(如果是这种情况)

$('#no_county_drop_down')。hide(); .post(src,{supplier:$('#lensType').val()},this.getSupplier);

else new error('No source was passed!');
$
$ b getSupplier:function(results){
if(!results)return;
counties.html(results);

$ ('#loading_county_drop_down')。hide(); //隐藏加载...
$('#county_drop_down')。s how(); //显示下拉列表
}
}
}();

populate();

});

PHP代码:

 <?php 
if(isSet($ _ POST ['supplier'])){

include'db.php';
$ b $ stmt = $ mysql-> prepare(SELECT DISTINCT SupplierBrand FROM plastic WHERE HeadingNo ='。$ _ POST ['supplier']。');
$ stmt-> execute();
$ stmt-> bind_result($ supplierBrand);

while($ row = $ stmt-> fetch()):?>

< option value =<?php echo $ supplierBrand;?> width =100px><?php echo $ supplierBrand; ?>< /选项>

我的问题是当我调试我注意到没有值传递给PHP脚本,这使得选择空。我试图通过萤火虫输出console.log跟踪或调试,并在这方面的失败。
请协助使用这个代码来显示一个单选按钮的动态列表。

解决方案

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

$ $ $''code $('#lensType')。val() < ---更改

类似于这样的内容:

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


I have radio buttons as shown below.

        <div id="lensType">

                        <input type="radio"  name="design" style="vertical-align: middle"  value="1"/>
                        <label for="design">Single Vision</label><br/>

                        <input type="radio" name="design" style="vertical-align: middle" value="2" />
                        <label for="material" >Accommodative Support</label><br/>

                        <input type="radio"  name="design" style="vertical-align: middle"  value="3"/>
                        <label for="design">Bifocal</label> <br/>

                        <input type="radio"   name="design" style="vertical-align: middle" value="4" />
                        <label for="material" >Varifocal (Intermediate/Near)</label><br/>

                        <input type="radio"   name="design" style="vertical-align: middle" value="5"/>
                        <label for="material" >Varifocal (Distance/Near)</label>

                    </div>

I am making a dynamic select. I have my javascript code that post the value . It seems the supplier value is now posted. Below is the code for my script.

  $(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 code :

<?php
  if(isSet($_POST['supplier'])) {

   include 'db.php';

  $stmt = $mysql->prepare("SELECT DISTINCT SupplierBrand FROM plastic WHERE          HeadingNo='".$_POST['supplier']."'");
  $stmt->execute();
  $stmt->bind_result($supplierBrand);

  while ($row = $stmt->fetch()) : ?>

 <option value="<?php echo $supplierBrand; ?>" width="100px"><?php echo $supplierBrand; ?></option>

My problem is when I debug I notice there is no value passed to the php script and this makes the select empty. I have tried to trace or debug by having firebug output the console.log and failed in this regard. Please assist with this code which is meant to show a dynamic list from a radio button selection.

解决方案

In your javascript you are getting the value of the div, not the radio button:

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

To something like this:

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

这篇关于如何使用萤火虫进行调试并显示单选按钮的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆