layui向body添加html_layui 各项配置
第一、如何全部選中table中每一條記錄
1.首先給table的父類設(shè)置一個(gè)唯一id *這種方式不推薦,效果比較差,推薦第2種方式
再搜索 alias-table div.layui-table-fixed.layui-table-fixed-l下面的i元素
var bbcc= $('#alias-table div.layui-table-fixed.layui-table-fixed-l
div.layui-table-cell.laytable-cell-1-0-0.laytable-cell-checkbox
div.layui-unselect.layui-form-checkbox i')
bbcc.each(function (index, element) {
element.click();
});
2.直接搜索layui-table-header,會(huì)搜索出3個(gè),直接選第2個(gè),具體如下
var html=$('.layui-table-header table i.layui-icon.layui-icon-ok')[1];
html.click();
第二、如何獲取彈出層iframe內(nèi)容
1.首先給iframe內(nèi)想要獲取的元素添加唯一的id2.具體如下:
$('#button-order-alladd').click(function () {
layer.open({
type:2,
title:"你好",
closeBtn:1,
area:["500px","320px"],
content:"{% url 'test:ceshi' %}",
btn:['確定', '取消'],
yes:function(index, layero){
var body=layer.getChildFrame('body',index); #使用layer.getChildFrame獲取iframe內(nèi)的body部分內(nèi)容
var test_t=body.find('#textarea-order').val(); #再通過(guò)find查到唯一的id
layer.close(index);
},
cancel:function(index, layero){
layer.close(index);
return false;
},
});
});
第三、如何利用iframe加載html(layer.open)
加載layui.layer,然后利用layer.open加載iframe
$('#button-order-alladd').click(function () {
layer.open({
type:2,
title:"批量增加",
closeBtn:1,
area:["500px","320px"],
content:"{% url 'ceshi:test' %}", #加載html路徑
btn:['確定', '取消'],
yes:function(index, layero){
var body=layer.getChildFrame('body',index);
var test_t=body.find('#textarea-order').val();
testdata=JSON.stringify(test_t.trim().split(" "));
layer.close(index);
$.ajax({
url:"{% url 'ceshi:data' %}",
method:"post",
headers: {"X-CSRFToken": token_value},
cache:false,
data:{
data:testdata,
check:checkSelect
},
success:function () {
table.reload('ordertest',{url:"{% url 'ceshi:data' %}",where:{"check":checkSelect}})
}
});
},
cancel:function(index, layero){
layer.close(index);returnfalse;
},
});
});
第四、iframe里的內(nèi)容如何選中radio按鈕,checkbox類同
接上第三,上面的layer.open的內(nèi)部操作,首先需要獲取到input元素
這樣是不可以操作,需要在元素加上$,讓它重新封裝成一個(gè)jquery元素,才可進(jìn)行一些,點(diǎn)擊操作,效果如下:
var body=layer.getChildFrame('body', index);
test=body.find("input[name='limits1']");
test_data=test; #用于下面的第三種方法,直接獲取iconfor (var n=0;n
if (test[n].title===obj.data.ceshi){
console.log('測(cè)試');
console.log(test[n]);#這個(gè)是獲取到純?cè)厝缟蠄D1,這樣是不可以操作例如。attr prop等都是不可以
console.log($(test[n])); #這個(gè)是對(duì)獲取到的純?cè)刂匦路庋b為jquery對(duì)象,才可以進(jìn)行操作,如上圖2
$(test[n]).attr('checked','checked');//test_data.eq(n).next('div').children('i.layui-anim.layui-icon').click(); #這是另外一方式,對(duì)icon進(jìn)行點(diǎn)擊,以達(dá)到選中,但需要在遍歷之前,先把值賦給另外一個(gè)變量,不能在當(dāng)前遍歷中進(jìn)行直接操作
}};
#執(zhí)行后,需要對(duì)form表單重新進(jìn)行刷新,否則是看不出效果,如果是使用icon點(diǎn)擊是不需要刷新,其它都需要刷新var iframeWin = layero.find('iframe')[0].contentWindow; #layero是layer.open中sucess里的參數(shù)
iframeWin.layui.form.render('radio');
總結(jié)
以上是生活随笔為你收集整理的layui向body添加html_layui 各项配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: springboot test_精益求精
- 下一篇: mysql blob 好处_MySQL中