HTML和JS中所谓的“焦点”是指什么?

html-css09

HTML和JS中所谓的“焦点”是指什么?,第1张

焦点在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')

}

})

没有焦点时就是正常的书写css代码

有焦点时就用伪元素:focus 来控制样式好了

或者使用jquery中的focus()和blur()方法

当元素获得焦点时,发生 focus 事件。

当元素失去焦点时,发生 blur 事件