前端JS问题

一个文本框显示员工姓名 ,一个隐藏表单员工的ID 但用户删除文本框的姓名后,另外一个隐藏的ID也要删除 ,这样怎样触发啊

阅读 3.1k
5 个回答

员工姓名文本框 为 A
员工ID文本框为 B
在A的onChange事件中,判断当value为""时,将B的value也设为""

<input type="text" id="name" value="" />
<input type="hidden" name="" id="id" value="" />
$(function(){
    $('#name').keyup(function(){
        if ($(this).val() == '') {
            $('#id').val('')    
        }
    })
})
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<input type="text" name="name" value="张三"  onchange="change(this)">
<input type="hidden" value="123"  id="B">
<script>
function change(obj) {
    if(obj.value=='') {
        document.getElementById('B').value=""
    }
}
</script>
</body>
</html>

监听键盘keydown或者keyup事件 判断员工姓名文本框是否为空 来决定员工ID是否需要删除

这个输入名字的文本框需要匹配吧、然后正确就获得uid、
username == “” ? uid:“”;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题