js里怎么做到在空白框输入一个A弹窗返回一个a其他值不予反应

JavaScript011

js里怎么做到在空白框输入一个A弹窗返回一个a其他值不予反应,第1张

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>首页配置</title>

<link rel="stylesheet" href="./rescource/style.css">

<script>

window.onload = function(){

var e = document.getElementById('e')

e.onkeyup= function(){

if(e.value.indexOf('A') != -1){

alert('a')

}

}

}

</script>

</head>

<body>

<h1 class="title">首页配置</h1>

<!-- Banner start -->

<section class="box">

<div class="box-left">

<input type="checkbox" name="banner">

<label for="banner">BANNER:</label>

</div>

<div class="box-right">

<div class="config-banner">

<div class="banner-img">

<img width="200" height="98" src="./rescource/5a30ccdfN9a1fa29c.jpg!q70.jpg" alt="">

</div>

<div class="banner-config">

<div class="form-item">

<label>Banner名称:</label>

<input id="e" type="text" class="w150 mr15" >

<label>页面跳转:</label>

<select class="w100">

<option value="健康" selected>健康</option>

<option value="自定义">自定义</option>

</select>

</div>

<div class="form-item">

<label>H5址:</label>

<input type="text" class="w250">

</div>

<div class="form-item">

<button type="button" class="button">修改图片</button>

<button type="button" class="button">移</button>

<button type="button" class="button">移</button>

<button type="button" class="button">删除</button>

</div>

</div>

</div>

<div class="submit-banner">

<button type="button" onclick="b()" class="button">添加Banner</button>

</div>

</div>

</section>

<!-- Banner end -->

</body>

</html>

1、限制输入空格

<input type="text" onkeyup="this.value=this.value.replace(/^ +| +$/g,' ')">

2、限制输入空格及英文状态下的逗号

<input type="text" onkeyup="this.value=this.value.replace(/[, ]/g,' ')">

3、限制空内容输入

<script>

    function myfunction() {

        var a = $("text1").val()

        if ($.trim(a) == "") {

                alert("不能为空!")

                return false

         }

  }

</script>