JavaScript寫的序列代碼產生器

來源:互聯網
上載者:User

今天一位網友向我求助,他要在Excel中填寫

 

PDAA20124527000001
PDAA20124527000002
PDAA20124527000003

這樣的序列,但在Excel中無法智能填充。

 

這個可以編寫VBA代碼來完成,不過我對VBA不太熟,還是用JavaScript寫了一個。

 

<FORM><p><font color="blue" size="+2">序列產生器 v0.0.0001</font></p><p>固定部分:<INPUT TYPE="text" ID="txtFixed" value="PDAA20124527" /></p><p>起始值:<INPUT TYPE="text" ID="txtBegin" value="1"> 結束值:<INPUT TYPE="text" ID="txtEnd" value="999999"> 步長:<INPUT TYPE="text" ID="txtStep" value="1"> <INPUT TYPE="button" VALUE="產生序列" ONCLICK="genCode();"></p></FORM><script language="javascript">function genCode(){sFixed = (document.getElementById("txtFixed")).value;if (0==sFixed.length){if (!confirm("未指示固定部分!\n要繼續產生嗎?")){return;}}iStart = (document.getElementById("txtBegin")).value;if (0==iStart.length){alert("未指示起始值!");return;}iStart = iStart/1;iEnd = (document.getElementById("txtEnd")).value;if (0==iEnd.length){alert("未指示結束值!");return;}iEnd = iEnd/1;iStep = (document.getElementById("txtStep")).value;if (0==iStep.length){if (!confirm("未指示結束值!\n要預設為1,繼續產生嗎?")){return;}}iStep = iStep/1;genSerialCode();}function genSerialCode(){document.write('<form name="frmTest">');document.write('<TEXTAREA ROWS="30" COLS="90" name="taTest">');for (i=iStart; i < iEnd+1; i+=iStep){document.write(sFixed);var j = i;while( (j = j*10) < iEnd ){//document.writeln("j="+j);document.write("0");}document.writeln(i);}document.write('<\/TEXTAREA><\/form>');var tempval=eval("document.frmTest.taTest");tempval.focus();tempval.select();therange=tempval.createTextRange();therange.execCommand("Copy");}</script>

 

改進了一下:

<FORM><p><font color="blue" size="+2">序列產生器 v0.0.0001</font></p><p>固定部分:<INPUT TYPE="text" ID="txtFixed" value="PDAA20124527" /></p><p>起始值:<INPUT TYPE="text" ID="txtBegin" value="1"> 結束值:<INPUT TYPE="text" ID="txtEnd" value="999999"> 步長:<INPUT TYPE="text" ID="txtStep" value="1"> <INPUT TYPE="button" VALUE="產生序列" ONCLICK="genCode();"></p></FORM><script language="javascript">function genCode(){sFixed = (document.getElementById("txtFixed")).value;if (0==sFixed.length){if (!confirm("未指示固定部分!\n要繼續產生嗎?")){return;}}iStart = (document.getElementById("txtBegin")).value;if (0==iStart.length){alert("未指示起始值!");return;}iStart = iStart/1;iEnd = (document.getElementById("txtEnd")).value;if (0==iEnd.length){alert("未指示結束值!");return;}iEnd = iEnd/1;iStep = (document.getElementById("txtStep")).value;if (0==iStep.length){if (!confirm("未指示結束值!\n要預設為1,繼續產生嗎?")){return;}}iStep = iStep/1;genSerialCode();}function genSerialCode(){document.write('<form name="frmTest">');document.write('<TEXTAREA ROWS="30" COLS="90" name="taTest">');var j, iMaxLen = String(iEnd).length;for (i=iStart; i < iEnd+1; i+=iStep){document.write(sFixed);var iLen = iMaxLen - String(i).length;for (j = 0; j < iLen; j++){//document.writeln("j="+j);document.write("0");}document.writeln(i);}document.write('<\/TEXTAREA><\/form>');var tempval=eval("document.frmTest.taTest");tempval.focus();tempval.select();therange=tempval.createTextRange();therange.execCommand("Copy");}</script>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.