手记

js 输入

<html>

<head>

  <meta charset="utf-8">

  <title>JS Bin</title>

</head>

<body>

 <ul id="haha">

        <li>a</li>

        <li>b</li>

        <li>c</li>

        <li>d</li>

        <li>e</li>

    </ul>

<input type="text" id="my">

<script>

var a = document.getElementById('haha');

var my=document.getElementById("my");


my.addEventListener("keyup",function(e){

let str=my.value;

let val=this.value;

let d=/\d{5}/g;

this.value=this.value.replace(this.value, function(word){

if(word.indexOf(".")===-1){

return word;

}else{

let arr=word.split(".");

let first=arr[0];

let last=arr[1].substr(0,2);

return first+"."+last;

}

}

  );

},false

)

haha.addEventListener('click',function (e){

if(e.target.tagName === 'LI'){

console.log('ok!')

}

})

//注意tagName是大写

</script>

</body>

</html>



0人推荐
随时随地看视频
慕课网APP