函数防抖

  |  
 阅读次数

函数防抖动

鼠标移入事件的函数防抖方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/** HTML */
<div
class="getTitle"
@mouseover="getTitleReq(scope)"
@mouseout="clearTitleReq"
></div>

/** 指标完成率 获取数据行说明 */
getTitleReq(scope) {
// console.log('getTitleTimeout');
clearTimeout(this.getTitleTimeout)
this.getTitleTimeout = setTimeout(() => {
// debugger
// 请求接口 doSomething...
}, 500)
},

/** 指标完成率 清除获取数据行说明 */
clearTitleReq() {
// console.log('clearTimeout');
clearTimeout(this.getTitleTimeout)
},

js之iframe父子页面通信

  |  
 阅读次数

js之iframe父子页面通信

父页面

1
2
3
4
5
6
7
8
9
10
11
12
/** 父页面需要在 window对象上 挂载一个 方法,供子页面调用 */
iframeHandle() {
window.clickSet = () => {
this.setState({
showReturn: true
})
}
}

componentDidMount() {
this.iframeHandle()
}

子页面

1
2
3
4
5
6
7
function clickSet() {
parent.window.clickSet(); // 子页面方法内部 调用父级window对象 下挂载的方法
}

$(function(){
$('.iframeReturn').on('click',clickSet) // 调用方法
})


iframe在更改了src之后对应的网页并未刷新

在更改src之前加上这一句即可。

document.getElementById(iframe的id).contentWindow.location.reload(true);

Iframe监听ulr

onload标签属性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<iframe
id="AirportBusiness"
src={ifSrc} frameBorder="0"
onLoad={this.handleButton}
style={{ border: 0, width: clientWidth, height: clientHeight, marginTop: -70 }}
>
</iframe>

handleButton() {
let ifra = document.getElementById('AirportBusiness').contentWindow.location.href;
let urlTest = /index/;
this.setState({
showReturn: !urlTest.test(ifra)
})
}