页面打开时发生的操作

时间:2015-10-25 00:59:38

标签: javascript html

页面打开时需要采取措施并删除底部

<form name="randform">
Account Number: &nbsp;<input type="text" name="randomfield"     value="">&nbsp;
<input type="button" value="Create Account Number" onClick="randomString();">

需要代码随时打开随机数

  function randomString() {
  var chars = "0123456789";
  var string_length = 10;
  var randomstring = '';
  for (var i=0; i<string_length; i++) {
       var rnum = Math.floor(Math.random() * chars.length);
       randomstring += chars.substring(rnum,rnum+1);
     }
  document.randform.randomfield.value = randomstring;
}

2 个答案:

答案 0 :(得分:0)

  

//页面打开时需要采取行动

尝试使用window.onload

&#13;
&#13;
<script>
  function randomString() {
    var chars = "0123456789";
    var string_length = 10;
    var randomstring = '';
    for (var i = 0; i < string_length; i++) {
      var rnum = Math.floor(Math.random() * chars.length);
      randomstring += chars.substring(rnum, rnum + 1);
    }
    document.randform.randomfield.value = randomstring;
  }
  window.onload = randomString;
</script>
<form name="randform">

  Account Number: &nbsp;
  <input type="text" name="randomfield" value="">&nbsp;
  <input type="button" value="Create Account Number" onclick="randomString();">
</form>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

<script>
    var main_form = "[data-inSet=hook]";
    var ActionFild = "[data-inSet=randomfield]";

    $(main_form).ready(function () {
        //the Function You want To Fire -=>
        //i am just traing to get window height and output in consol :-p
        console.log( window.innerHeight+"px");//my action
    });
    /*
    u can also run the function  if the input load . just change $(main_form) -=> [ to ] <=-$(ActionFild);
    need more info plz comment bellow 
    */``
</script>