在layer.open弹窗中,content属性链接的是其他地址(test.html),在layer.open的按钮中如何触发test.html内的安妮
时间: 2024-05-05 16:19:43 浏览: 11
可以在test.html中定义一个函数,例如:
```javascript
function myFunction() {
alert("Hello! I am Anne.");
}
```
然后在layer.open的按钮中,使用JavaScript调用该函数,例如:
```javascript
layer.open({
content: 'test.html',
btn: ['触发安妮'],
yes: function(index, layero){
// 触发test.html中的myFunction函数
layero.find('iframe')[0].contentWindow.myFunction();
layer.close(index);
}
});
```
这样点击按钮时,就可以触发test.html中定义的myFunction函数,弹出包含“Hello! I am Anne.”的提示框。
相关问题
layui中layer.open中content属性传入'demo.html'被识别成字符串怎么解决
如果您想在 `layer.open` 中使用 `demo.html` 页面作为 content,可以使用以下代码:
```javascript
layer.open({
type: 2,
content: 'demo.html'
});
```
其中 `type: 2` 表示以 iframe 层方式打开,`content: 'demo.html'` 表示要加载的页面路径。如果您要传递参数给 `demo.html` 页面,可以在路径后面拼接参数,例如:
```javascript
layer.open({
type: 2,
content: 'demo.html?id=1&name=test'
});
```
在 `demo.html` 页面中可以使用 `window.location.search` 获取传递过来的参数。
layer.style自定义layer.open
layer.style自定义layer.open是可以的。可以通过设置skin属性来自定义弹窗的样式。你可以参考以下的代码:
layer.open({
type: 1,
title: "test",
closeBtn: 1,
area: ['420px', '200px'],
scrollbar: false,
skin: 'my-layer1', // 自定义样式的class名
shadeClose: true,
content: img,
fixed:false,
top:10,
end: function () {}
});
在这个例子中,通过设置skin属性为'my-layer1',你可以自定义弹窗的样式。你可以根据自己的需求定义新的class名,并在样式文件中设置对应的样式规则。这样即可实现自定义的layer.open弹窗样式。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [layer.open自定义弹出位置](https://blog.csdn.net/hofmann/article/details/103026244)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [layui中layer.open中select失效,表格中插入图片,checkbox是否选中,查看大图,parent.layer.open中失效](https://blog.csdn.net/hangGe0111/article/details/85066730)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]