這次帶給大家實現輸入框與下拉框連動效果,實現輸入框與下拉框聯動效果的注意事項有哪些,下面就是實戰案例,一起來看一下。
如圖:
#html程式碼
<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['material_id']}">{$value['material_name']}</option> {/foreach} </select> </td> </tr>
JQuery程式碼
<script type="text/javascript"> $('#reward').bind('input propertychange', 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='"+key+"'>"+obj[key]+"</option>"; reward_id.append(option); } } } }); } </script>
public function add_alms() { $reward = $this->materials->selReward(); $this->assign('reward',$reward); return $this->fetch(); } public function do_add_alms() { $data = Request::instance()->param(); $this->alms->addAlms($data); }
相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
#以上是實現輸入框與下拉框聯動效果的詳細內容。更多資訊請關注PHP中文網其他相關文章!