dongshuzhuo5659 2018-08-01 13:15
浏览 258
已采纳

如何通过id -jquery获取动态值

Actually, I have a field name (industry) the problem is that I want to get two value from the database change of industry by jquery but how do I do this can't understand. Please help-

Here is my code-

 <label>Select Type of Industry</label>
          <select class="form-control" name="industry" id="industry"  onchange="industry_id(this.value);" required="">
          <option value="">------------------Select Your Industry----------------</option> 
           <?php 
                          foreach ($industry as $key => $value) { ?>
                          <option value="<?= $value['id']; ?> "> <?= $value['industory']; ?></option>    
                    <?php } ?> 
          </select> 
  </div> 
  <script>
                 function industry_id(value) {
                   $.get("<?php echo base_url()?>dive/getebitvalue/"+value,function (data) {
                        $("#ebit_name").html(data);
                        // alert(data);
                      });
                    }
                  </script>

one value I get easily but how to get second from the same id?

Here is my model---

function getebit()
    {
        $industry=$this->uri->segment(3);
        $sql = $this->db->query('SELECT * FROM industry WHERE id='.$industry);
        $result = $sql->result();
        $html='';
        foreach ($result as $data) {
            $html.= "<option value='" . $data->ebit . "' >" . $data->ebit  . "</option>";
        }
        echo $html;
    }

}

and here is my controller--

function getebitvalue(){
        $data['ebit']= $this->site_model->getebit();
    }
  • 写回答

2条回答 默认 最新

  • duancheng6500 2018-08-02 10:37
    关注
    You can also do this-
    
    view page-
    
    
    
        <div class="form-group">
            <label>Select Type of Industry</label>
              <select class="form-control industryData" name="industry" id="industry"  required="">
              <option value="">------------------Select Your Industry----------------</option> 
               <?php 
                              foreach ($industry as $value) { ?>
                              <option data1="<?php echo $value['ebitda']; ?>" data2="<?php echo $value['ebit']; ?>" value="<?= $value['id']; ?>"> <?= $value['industory']; ?></option>    
                        <?php } ?> 
              </select> 
          </div> 
    
    
    model page-
    
    
        function select($tbl,$con=''){
                $this->db->select("*");
                $this->db->from($tbl);
                if(!empty($con))
                    $this->db->where($con);
    
                $query = $this->db->get();
                return $query->result();
            }
    
    
    controller page-
    
    
    
    
    public function dive(){
            $this->load->view('common/header');
            $data['industry'] = $this->site_model->select('industry');
            $this->load->view('dive/dive',$data);
            $this->load->view('common/footer');
        }
    
    
    
    Now use jquery on your view page--
    
        <script>
    
        $(document).on("change", ".industryData", function () {
        var value = $(this).val(); 
        var data1 = $('.industryData option:selected ').attr('data1'); 
        var data2 = $('.industryData option:selected ').attr('data2'); 
    
        alert(data1);
    
        });
        </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条