💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# layer弹出层 官方文档<http://layer.layui.com/> <https://cdn.bootcss.com/layer/2.3/layer.js> <https://github.com/logoove/jqueryplus/blob/master/layer/layer.css>不需要加载图片了,已经base64 ``` <pre class="calibre14">``` layer<span class="token2">.</span><span class="token1">alert</span><span class="token2">(</span><span class="token4">'内容'</span><span class="token2">)</span><span class="token2">;</span> layer<span class="token2">.</span><span class="token1">alert</span><span class="token2">(</span><span class="token4">'内容'</span><span class="token2">,</span> <span class="token2">{</span> icon<span class="token2">:</span> <span class="token3">1</span><span class="token6">//1蓝色对号 2红色错误 3橙色问号4灰色锁 5红色哭脸</span> <span class="token2">}</span><span class="token2">)</span> layer<span class="token2">.</span><span class="token1">msg</span><span class="token2">(</span><span class="token4">'玩命提示中'</span><span class="token2">)</span><span class="token2">;</span> <span class="token3">0</span>文本<span class="token3">1</span>密码<span class="token3">2</span>文本域 layer<span class="token2">.</span><span class="token1">prompt</span><span class="token2">(</span><span class="token2">{</span>title<span class="token2">:</span> <span class="token4">'请输入'</span><span class="token2">,</span> formType<span class="token2">:</span> <span class="token3">0</span><span class="token2">}</span><span class="token2">,</span> <span class="token5">function</span><span class="token2">(</span>text<span class="token2">,</span> index<span class="token2">)</span><span class="token2">{</span> layer<span class="token2">.</span><span class="token1">msg</span><span class="token2">(</span>text<span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> <span class="token6">//询问框</span> layer<span class="token2">.</span><span class="token1">confirm</span><span class="token2">(</span><span class="token4">'您是如何看待前端开发?'</span><span class="token2">,</span> <span class="token2">{</span> btn<span class="token2">:</span> <span class="token2">[</span><span class="token4">'重要'</span><span class="token2">,</span><span class="token4">'奇葩'</span><span class="token2">]</span> <span class="token6">//按钮</span> <span class="token2">}</span><span class="token2">,</span> <span class="token5">function</span><span class="token2">(</span><span class="token2">)</span><span class="token2">{</span> layer<span class="token2">.</span><span class="token1">msg</span><span class="token2">(</span><span class="token4">'的确很重要'</span><span class="token2">,</span> <span class="token2">{</span>icon<span class="token2">:</span> <span class="token3">1</span><span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span><span class="token2">,</span> <span class="token5">function</span><span class="token2">(</span><span class="token2">)</span><span class="token2">{</span> layer<span class="token2">.</span><span class="token1">msg</span><span class="token2">(</span><span class="token4">'也可以这样'</span><span class="token2">,</span> <span class="token2">{</span> time<span class="token2">:</span> <span class="token3">20000</span><span class="token2">,</span> <span class="token6">//20s后自动关闭</span> btn<span class="token2">:</span> <span class="token2">[</span><span class="token4">'明白了'</span><span class="token2">,</span> <span class="token4">'知道了'</span><span class="token2">]</span> <span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> <span class="token6">//捕获页</span> layer<span class="token2">.</span><span class="token1">open</span><span class="token2">(</span><span class="token2">{</span> type<span class="token2">:</span> <span class="token3">1</span><span class="token2">,</span> shade<span class="token2">:</span> <span class="token3">false</span><span class="token2">,</span> title<span class="token2">:</span> <span class="token3">false</span><span class="token2">,</span> <span class="token6">//不显示标题</span> content<span class="token2">:</span> $<span class="token2">(</span><span class="token4">'.layer_notice'</span><span class="token2">)</span><span class="token2">,</span> <span class="token6">//捕获的元素,注意:最好该指定的元素要存放在body最外层,否则可能被其它的相对元素所影响</span> cancel<span class="token2">:</span> <span class="token5">function</span><span class="token2">(</span><span class="token2">)</span><span class="token2">{</span> layer<span class="token2">.</span><span class="token1">msg</span><span class="token2">(</span><span class="token4">'捕获就是从页面已经存在的元素上,包裹layer的结构'</span><span class="token2">,</span> <span class="token2">{</span>time<span class="token2">:</span> <span class="token3">5000</span><span class="token2">,</span> icon<span class="token2">:</span><span class="token3">6</span><span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span> <span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> <span class="token6">//页面层</span> layer<span class="token2">.</span><span class="token1">open</span><span class="token2">(</span><span class="token2">{</span> type<span class="token2">:</span> <span class="token3">1</span><span class="token2">,</span> skin<span class="token2">:</span> <span class="token4">'layui-layer-rim'</span><span class="token2">,</span> <span class="token6">//加上边框</span> area<span class="token2">:</span> <span class="token2">[</span><span class="token4">'420px'</span><span class="token2">,</span> <span class="token4">'240px'</span><span class="token2">]</span><span class="token2">,</span> <span class="token6">//宽高</span> content<span class="token2">:</span> <span class="token4">'html内容'</span> <span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> layer<span class="token2">.</span><span class="token1">tips</span><span class="token2">(</span><span class="token4">'Hi,我是tips'</span><span class="token2">,</span> <span class="token4">'吸附元素选择器,如#id'</span><span class="token2">)</span><span class="token2">;</span> <span class="token6">//相册层</span> $<span class="token2">.</span><span class="token1">getJSON</span><span class="token2">(</span><span class="token4">'test/photos.json?v='</span><span class="token">+</span><span class="token5">new</span> <span class="token1">Date</span><span class="token2">,</span> <span class="token5">function</span><span class="token2">(</span>json<span class="token2">)</span><span class="token2">{</span> layer<span class="token2">.</span><span class="token1">photos</span><span class="token2">(</span><span class="token2">{</span> photos<span class="token2">:</span> json <span class="token6">//格式见API文档手册页</span> <span class="token2">,</span>anim<span class="token2">:</span> <span class="token3">5</span> <span class="token6">//0-6的选择,指定弹出图片动画类型,默认随机</span> <span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> <span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> <span class="token6">//tab层</span> layer<span class="token2">.</span><span class="token1">tab</span><span class="token2">(</span><span class="token2">{</span> area<span class="token2">:</span> <span class="token2">[</span><span class="token4">'600px'</span><span class="token2">,</span> <span class="token4">'300px'</span><span class="token2">]</span><span class="token2">,</span> tab<span class="token2">:</span> <span class="token2">[</span><span class="token2">{</span> title<span class="token2">:</span> <span class="token4">'TAB1'</span><span class="token2">,</span> content<span class="token2">:</span> <span class="token4">'内容1'</span> <span class="token2">}</span><span class="token2">,</span> <span class="token2">{</span> title<span class="token2">:</span> <span class="token4">'TAB2'</span><span class="token2">,</span> content<span class="token2">:</span> <span class="token4">'内容2'</span> <span class="token2">}</span><span class="token2">,</span> <span class="token2">{</span> title<span class="token2">:</span> <span class="token4">'TAB3'</span><span class="token2">,</span> content<span class="token2">:</span> <span class="token4">'内容3'</span> <span class="token2">}</span><span class="token2">]</span> <span class="token2">}</span><span class="token2">)</span><span class="token2">;</span> 点击小图看大图 ``` ``` $(document).on("click","img.big",function(e){ layer.photos({ photos: { "data": \[{"src": e.target.src}\] } }); }); ``` <pre class="calibre16">``` ``` ```