Home > Web Front-end > JS Tutorial > body text

Realize linkage between input box and drop-down box

亚连
Release: 2018-06-09 17:53:55
Original
3103 people have browsed it

Below I will share with you an example of real-time monitoring of input boxes and realization of linkage between input boxes and drop-down boxes. It has a good reference value and I hope it will be helpful to everyone.

As shown in the picture:

##html code

<tr>
 <th scope="row">奖励类型:</th>
 <td><input value="" type="text" name="item" id="reward" style="width: 60px;height: 20px;" placeholder="输入关键字" />
  <select name="reward_id" id="reward_id"> 
   <option value="">---请选择---</option>
   {foreach $reward as $value}
   <option value="{$value[&#39;material_id&#39;]}">{$value[&#39;material_name&#39;]}</option>
   {/foreach}
  </select>
 </td>
</tr>
Copy after login

JQuery code

<script type="text/javascript">
 $(&#39;#reward&#39;).bind(&#39;input propertychange&#39;, function() {reward();});
 function reward()
 {
  var search = $("#reward").val();
  $.ajax({ 
   type:"get", 
   url:"/mall/config_commodity_info/search_commodity_info", 
   data:{search:search}, 
   success:function(select){ 
     var reward_id = $("#reward_id"); 
     if (select) {
     $("option",reward_id).remove();
     var obj = JSON.parse(select);
     for (var key in obj) {
      var option = "<option value=&#39;"+key+"&#39;>"+obj[key]+"</option>"; 
      reward_id.append(option); 
     }
     } 
   } 
 });
 } 
</script>
Copy after login

PHP code

public function add_alms()
{
 $reward = $this->materials->selReward();
 $this->assign(&#39;reward&#39;,$reward);
 return $this->fetch();
}
public function do_add_alms()
{
 $data = Request::instance()->param();
 $this->alms->addAlms($data);
}
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to read data through json files in Vue2.5

Using http in vue2.5.2 Request how to get static json data

Using plugin owlcarousel in jQuery slideshow (detailed tutorial)

In ES6 arrow function about this The problem?

What are the methods to use echarts3.0 adaptive in vue?

How to solve the problem of sliding failure of dynamically loaded data in swiper?

The above is the detailed content of Realize linkage between input box and drop-down box. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!