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

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 事件

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

<!DOCTYPE html>  

<html>  

<head>  

    <meta charset="UTF-8"/>  

    <title>checkValidity 示例</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>

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

  </tr>

  <tr>

    <td><input name="pwd" type="password" placeholder="密码"></td>

  </tr>

  <tr>

    <td><input 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

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-19
下一篇 2023-03-19

发表评论

登录后才能评论

评论列表(0条)

保存