How to generate Unique ID without form submission in php ajax

This question already has an answer here:

  • Create GUID / UUID in JavaScript? 49 answers

  • 您可以将onchange事件附加到您的输入。

    <form method="post" action="">
    <input type="text" name="name" id="name" onchange="my_validate_func()">
    <input type="text" name="phone" id="phone" onchange="my_validate_func()">
    <input type="text" name="course" id="course" onchange="my_validate_func()">
    <input type="text" name="center" id="center" onchange="my_validate_func()">
    <input type="text" name="roll" id="roll">
    <button type="submit">Submit</button>
    

    function my_validate_func (){ 
       if($('#name').val()!="" && $('#phone').val()!="" && $('#course').val()!="" && $('#center').val()!=""){
           $.ajax({
             url:'your_url',
             success: function(response){
                $('#roll').val(response.roll_num);
             }
           });
       }
    }
    
    链接地址: http://www.djcxy.com/p/16250.html

    上一篇: 数字字符串在JavaScript中?

    下一篇: 如何在没有提交表单的情况下在php ajax中生成唯一标识