html代码:
<dl class="row"> <dt class="tit"> <label for="title"><em>*</em>编号</label> </dt> <dd class="opt"> <input type="text" name="number" value="" id="number" class="input-txt" maxlength="100"> <span class="err"></span> <p class="notic"></p> </dd> </dl>
jq代码:
function randomStr(len, arr) { var ans = ''; for(var i = len; i > 0; i--) { ans += arr[Math.floor(Math.random() * arr.length)]; } return ans; } $(function () { var number = randomStr(8, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); $("#number").attr("value",number);//替换掉input的value值 })