亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

解決layer.open彈出框不能獲取input框的值為空的問題

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

最近使用layer框架來做頁面彈出框操作??偸遣荒塬@取彈出框中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>品牌名稱:
  </div>
  <div>
  <input name="brandname" id="brandname" type="text" value=""/>
  </div>
  </div>
 </form>
</div>

彈出框如下圖:

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

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

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

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

相關(guān)文章

最新評(píng)論