焦點在HTML和JS中是只光標。
焦點在JS和HTML裏是在頁面上屏幕中閃動的小豎線,鼠標點擊就可獲得光標,Tab鍵可按照設置的Tabindex來進行切換焦點。
示例:
<divid="demo"></div>
<divid="test"></div>
<divid="one"></div>
<divid="two"></div>
<divid="three"></div>
<divid="fore"></div>
<divid="five"></div>
<divid="six"></div>
<script>
function$(id){
returndocument.getElementById(id);
}
$("demo").style.backgroundColor="green";
//調用方法
$("test").style.backgroundColor="blue";
$("one").style.backgroundColor="orange";
$("two").style.backgroundColor="red";
$("three").style.backgroundColor="purple";
$("fore").style.backgroundColor="#f6e71f";
$("five").style.backgroundColor="#5153ff";
$("six").style.backgroundColor="#ff1496";
//調用函數,並直接修改盒子的背景顏色
擴展資料
jquery判斷input輸入框的值
//輸入框正在輸入時
$("#ipt").on('input',function(){
if(!($('#ipt').val()=='')){
$(".cancle_ico").removeClass('hide');
}else{
$(".cancle_ico").addClass('hide');
}
})
//輸入框得到焦點時
$("#ipt").on('focus',function(){
if(!($('#ipt').val()=='')){
$(".cancle_ico").removeClass('hide');
}else{
$(".cancle_ico").addClass('hide');
}
})
//輸入框失去焦點時
$("#ipt").on('blur',function(){
if(($('#ipt').val()=='')){
$(".cancle_ico").addClass('hide');
}else{
$(".cancle_ico").removeClass('hide');
}
})