var IframeOnClick = {
resolution: 200,
iframes: [ ],
interval:null,
Iframe:function() {
this.element = arguments[0]
this.cb = arguments[1]
this.hasTracked =false
},
track:function(element, cb) {
this.iframes.push(newthis.Iframe(element, cb))
if (!this.interval) {
var _this =this
this.interval = setInterval(function() { _this.checkClick() },this.resolution)
}
},
checkClick:function() {
if (document.activeElement) {
var activeElement = document.activeElement
for (var iinthis.iframes) {
if (activeElement ===this.iframes[i].element) {// user is in this Iframe
if (this.iframes[i].hasTracked ==false) {
this.iframes[i].cb.apply(window, [])
this.iframes[i].hasTracked =true
}
}else {
this.iframes[i].hasTracked =false
}
}
}
}
}
最后直接调用
IframeOnClick.track(document.getElementById("iFrame"),function() { alert('a click') })
importjava.awt.BorderLayout
importjava.awt.event.ActionEvent
importjava.awt.event.ActionListener
importjava.util.ArrayList
importjava.util.List
importjava.util.Timer
importjava.util.TimerTask
importjavax.swing.JButton
importjavax.swing.JFrame
importjavax.swing.JLabel
importjavax.swing.SwingUtilities
publicclassTimerDemo{
publicstaticvoidmain(String[]args){
SwingUtilities.invokeLater(newRunnable(){
@Override
publicvoidrun(){
newTimerDemo().newTimerFrame()
}
})
}
classTimerFrameextendsJFrame{
privatestaticfinallongserialVersionUID=281511492706800685L
JLabellabel=null
JButtonbutton=null
List<Timer>list=newArrayList<Timer>()
publicTimerFrame(){
JFrameframe=newJFrame()
frame.setSize(300,200)
label=newJLabel()
button=newJButton("开始计时")
button.addActionListener(newActionListener(){
publicvoidactionPerformed(ActionEventarg0){
finalTimertimer=newTimer()
for(Timertim:list){
tim.cancel()
}
list.clear()
if(list.isEmpty()){
list.add(timer)
}
timer.schedule(newTimerTask(){
privateintcount=30
@Override
publicvoidrun(){
if(count>0){
SwingUtilities.invokeLater(newRunnable(){
@Override
publicvoidrun(){
label.setText(""+String.valueOf(count--)+"秒")
}
})
}else{
timer.cancel()
SwingUtilities.invokeLater(newRunnable(){
@Override
publicvoidrun(){
label.setText("时间到!")
}
})
}
}},0,1000)
}
})
frame.getContentPane().add(label,BorderLayout.NORTH)
frame.getContentPane().add(button,BorderLayout.SOUTH)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setVisible(true)
}
}
}
扩展资料
<divclass="row"id="row"onclick="A()B()">
<scripttype="text/javascript"src="">
functionA(){
alert("aaa")
}
functionB(){
alert("bbb")
}
</script>
第一步、绑定单击事件;button1.Click+=new EventHandler(but_Click)
第二步、编写Click事件处理方法;
private void but_Click(object sender, EventArgs e)
{
//Click事件处理内容
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)