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

您所在的位置:网站首页 获取焦点时是什么意思 HTML和JS中所谓的“焦点”是指什么?

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

2023-03-23 10:19| 来源: 网络整理| 查看: 265

焦点在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 事件

简单改了下你的,效果实现了,规范的写法自己改改吧

!DOCTYPE html  

html  

head  

    meta charset="UTF-8"/  

    titlecheckValidity 示例/title 

    style

      input.dd::-webkit-input-placeholder{

          color: red

          opacity:1

      } 

       

    /style

/head  

body 

form action="" method="get"

table width="200%" border="0" cellspacing="0" cellpadding="0" 

  tr

    tdinput class='' id='id' name="uname" type="text" placeholder="ID" onblur="aa(this)"/td

  /tr

  tr

    tdinput name="pwd" type="password" placeholder="密码"/td

  /tr

  tr

    tdinput name="" type="submit"/td

  /tr

/table

/form

script 

  function aa(a){

      if(a.value==''){

        a.placeholder='ID不能为空'

       a.className="dd"

      }

  }

/script

/body  

/html

欢迎分享,转载请注明来源:内存溢出

原文地址:https://outofmemory.cn/zaji/6256077.html



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3