欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解決layer.open彈出框不能獲取input框的值為空的問(wèn)題

 更新時(shí)間:2019年09月10日 08:55:54   作者:jaryle  
今天小編就為大家分享一篇解決layer.open彈出框不能獲取input框的值為空的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

最近使用layer框架來(lái)做頁(yè)面彈出框操作??偸遣荒塬@取彈出框中input的值,代碼如下:紅色標(biāo)記區(qū)域

添加js代碼

 //Ajax添加品牌
 function addBrandWI(){
 layer.open({
  type: 0,
  title: '品牌添加',
  shadeClose: true,
  shade: 0.8,
  btn: ['保存', '取消'],
  area: ['40%', '70%'],
  content: $('#add_Brand').html(),
  yes:function(index, layero){
  subForm();
  layer.close(index);
  },cancel: function(){}
 }); 
 }
 
 function subForm(){
 var bname=$("#brandname").val();
 $.ajax({
   url: 'salecenter.jsp?act=savaBrand&bname='+bname,
   type: "GET",
   dataType: "json", //返回json格式的數(shù)據(jù)
   async: true,
   success: function (data) {
    if (data == '0') {
    layer.alert("品牌添加成功");
    } else if(data == '1'){
    layer.alert("品牌添加失敗");
    }else if(data == '2'){
    layer.alert("此品牌已經(jīng)存在");
    }
   }, error: function() {
   }
  });
 }

添加html代碼

<!-- 彈出框添加品牌 -->
<div id="add_Brand" style="display:none;">
 <form autocomplete="off" id="sub_form" method="post">
  <div class="add_model">
  <div>
  <b class="out">*</b>品牌名稱(chēng):
  </div>
  <div>
  <input name="brandname" id="brandname" type="text" value=""/>
  </div>
  </div>
 </form>
</div>

彈出框如下圖:

點(diǎn)擊保存就是不能獲取input的值,總是為空字符串。

后來(lái)在網(wǎng)上查找資料,原來(lái)這是個(gè)比較普遍的bug,原來(lái)是layer.open的content參數(shù)(上面紅色標(biāo)記代碼),應(yīng)該寫(xiě)成

content: $('#add_Brand'),不要后面的html(),去掉后調(diào)試正常獲取了input的值,解決問(wèn)題就行,也沒(méi)有去深究這個(gè)是什么原因(關(guān)鍵也沒(méi)那個(gè)時(shí)間)。

以上這篇解決layer.open彈出框不能獲取input框的值為空的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論