input输入框中oninput属性的应用

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style> 
        body { 
            text-align:center; 
        } 
        h1 { 
            color:green; 
        } 
    style> 
    <title>oninput属性的使用title>
head>
<body>
    <h1>oninput 属性的使用h1> 
    <h2>oninput是HTML5中新增的属性h2> 
    
    在此处输入一些文字:<input type="text" id="ipt" oninput="oninputTest(this)"> 
    <p id="pTag">p>
    <hr>
    
    只能输入数字: <input type="text" id="ipt" oninput="value=value.replace(/[^\d]/g,'')">
    <hr>
    <hr>
    <hr>

    
    <input type="text" oninput="value=value.replace(/[^(?!:)\d]/g,'')">
body>
<script>
    function oninputTest(obj) { 
        document.getElementById("pTag").innerHTML = "输入的文字是:" + obj.value; 
    } 
script>
html>

你可能感兴趣的:(前端,html,html5)