我在HTML里设置了一个文本框给文本框设了个ID,然后我在JS里设置了一个获取本地时间的方法然后通过document.getElementById().value的形式传给文本框。现在我想有JQuery 里的keydown()方法使我键盘点击时文本框里的时间消失。求大神帮帮忙
用focus事件就行了
window.onload=function(){//这样赋值不用起函数名,起了也没用
//...你原来的代码
$('#clock,#clock2').focus(function(){this.value=''})
}
那在你触发的时候清空value不就好了
btn.onkeydown = function(){
document.getElementById('clock').value = '' ;
}
var TimeBtn=document.getElementById('TimeBtn'); TimeBtn.value=new Date();//这里的new Date() 换成你的showTime()方法就行 TimeBtn.onfocus = function(){ TimeBtn.value = ' ' ; } TimeBtn.onblur = function(){ TimeBtn.value = new Date() ; }var TimeBtn=document.getElementById('TimeBtn'); TimeBtn.value=new Date();//这里的new Date() 换成你的showTime()方法就行 TimeBtn.onfocus = function(){ TimeBtn.value = ' ' ; } TimeBtn.onblur = function(){ TimeBtn.value = new Date() ; }