栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

设置AJAX响应选中的单选按钮

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

设置AJAX响应选中的单选按钮

$('#editVehicle').find(':radio[name=drive][value="1"]').prop('checked', true);

样品:


$(function() {  response = {    "vehicle_id": 2,    "vehicle": "RENAULT TWINGO2798",    "seats": 43,    "luggage": 5,    "doors": 34,    "emission": 455,    "drive": "Manual",    "aircon": "Yes",    "price": "435.000"  };  console.log(response.drive);  if (response.drive == 'Manual')    $('#editVehicle').find(':radio[name=drive][value="1"]').prop('checked', true);  else    $('#editVehicle').find(':radio[name=drive][value="2"]').prop('checked', true);});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div id="editVehicle">  <div >    <label for="">Transmission :</label>    <div >      <label >        <input type="radio" name="drive" id="" value="1">Manual      </label>      <label >        <input type="radio" name="drive" id="" value="2">Auto      </label>    </div>  </div></div>

编辑:

更改。

if (response.drive == 'Manual'){          .find(':radio[name=drive][value="1"]').prop('checked', true)      } else {          .find(':radio[name=drive][value="2"]').prop('checked', true)      }

if (response.drive == 'Manual'){          $('#editVehicle').find(':radio[name=drive][value="1"]').prop('checked', true)      } else          $('#editVehicle').find(':radio[name=drive][value="2"]').prop('checked', true)      }

$('.editVehicle').on('click', function() { // Get the record's ID via attribute var id = $(this).attr('data-id'); var vehicleId = 'vehicleId=' + id; $.ajax({         url: './includes/ajaxprocess_edit_vehicles.php',         method: 'post',         data: vehicleId }).success(function(response) {         // Populate the form fields with the data returned from server         response = jQuery.parseJSON(response)         $('#editVehicle')      .find('[name="vehicle_id"]').val(response.vehicle_id).end()      .find('[name="vehicle_name"]').val(response.vehicle).end()      .find('[name="seats"]').val(response.seats).end()      .find('[name="luggage"]').val(response.luggage).end()      .find('[name="doors"]').val(response.doors).end()      .find('[name="emission"]').val(response.emission).end();      if (response.drive == 'Manual'){          $('#editVehicle').find(':radio[name=drive][value="1"]').prop('checked', true)      } else {          $('#editVehicle').find(':radio[name=drive][value="2"]').prop('checked', true)      }    $('#editVehicle').find('[name="rental"]').val(response.price).end();  // Show the dialog  bootbox          .dialog({       title: 'Edit This Vehicle',       message: $('#editVehicle'),       show: false // We will show it manually later          })          .on('shown.bs.modal', function() {       $('#editVehicle')    .show() // Show the edit form    .formValidation('resetForm'); // Reset form          })          .on('hide.bs.modal', function(e) {       // Bootbox will remove the modal (including the body which contains the edit form)       // after hiding the modal       // Therefor, we need to backup the form       $('#editVehicle').hide().appendTo('body');          })          .modal('show');     });        });


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/427427.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号