JS【JS时分秒时间控件】和js 折扣控件

来源:互联网 发布:视频添加二维码软件 编辑:程序博客网 时间:2024/05/28 15:55

 

鼠标点击 后 的效果 

SetTime.js

[javascript] view plaincopy
  1. /**//*********************************** 
  2. * 简单时间控件: version 1.0 
  3. * 作者:李禄燊  
  4. * 时间:2007-10-31 
  5.  
  6. * 使用说明: 
  7. * 首先把本控件包含到页面  
  8. * <script src="XXX/setTime.js" type="text/javascript"></script> 
  9. * 控件调用函数:_SetTime(field) 
  10. * 例如 <input name="time" type="text"   onclick="_SetTime(this)"/> 
  11. * 
  12. ************************************/  
  13. var str = "";  
  14. document.writeln("<div id=\"_contents\" style=\"padding:6px; background-color:#E3E3E3; font-size: 12px; border: 1px solid #777777;  position:absolute; left:?px; top:?px; width:?px; height:?px; z-index:1; visibility:hidden\">");  
  15. str += "\u65f6<select name=\"_hour\">";  
  16. for (h = 0; h <= 9; h++) {  
  17.     str += "<option value=\"0" + h + "\">0" + h + "</option>";  
  18. }  
  19. for (h = 10; h <= 23; h++) {  
  20.     str += "<option value=\"" + h + "\">" + h + "</option>";  
  21. }  
  22. str += "</select> \u5206<select name=\"_minute\">";  
  23. for (m = 0; m <= 9; m++) {  
  24.     str += "<option value=\"0" + m + "\">0" + m + "</option>";  
  25. }  
  26. for (m = 10; m <= 59; m++) {  
  27.     str += "<option value=\"" + m + "\">" + m + "</option>";  
  28. }  
  29. str += "</select> \u79d2<select name=\"_second\">";  
  30. for (s = 0; s <= 9; s++) {  
  31.     str += "<option value=\"0" + s + "\">0" + s + "</option>";  
  32. }  
  33. for (s = 10; s <= 59; s++) {  
  34.     str += "<option value=\"" + s + "\">" + s + "</option>";  
  35. }  
  36. str += "</select> <input name=\"queding\" type=\"button\" onclick=\"_select()\" value=\"\u786e\u5b9a\" style=\"font-size:12px\" /></div>";  
  37. document.writeln(str);  
  38. var _fieldname;  
  39. function _SetTime(tt) {  
  40.     _fieldname = tt;  
  41.     var ttop = tt.offsetTop;    //TT控件的定位点高  
  42.     var thei = tt.clientHeight;    //TT控件本身的高  
  43.     var tleft = tt.offsetLeft;    //TT控件的定位点宽  
  44.     while (tt = tt.offsetParent) {  
  45.         ttop += tt.offsetTop;  
  46.         tleft += tt.offsetLeft;  
  47.     }  
  48.     document.all._contents.style.top = ttop + thei + 4;  
  49.     document.all._contents.style.left = tleft;  
  50.     document.all._contents.style.visibility = "visible";  
  51. }  
  52. function _select() {  
  53.     _fieldname.value = document.all._hour.value + ":" + document.all._minute.value + ":" + document.all._second.value;  
  54.     document.all._contents.style.visibility = "hidden";  
  55. }  

折扣js:

[javascript] view plaincopy
  1. /**//*********************************** 
  2. * 简单折扣控件: 
  3. * 使用说明: 
  4. * 首先把本控件包含到页面  
  5. * <script src="XXX/SetAgio.js" type="text/javascript"></script> 
  6. * 控件调用函数:_SetAgio(field) 
  7. * 例如 <input name="Agio" type="text"   onclick="_SetAgio(this)"/> 
  8. * 
  9. ************************************/  
  10. var str = "";  
  11. document.writeln("<div id=\"_contents\" style=\"padding:6px; width:300px;background-color:#E3E3E3; font-size: 12px; border: 1px solid #777777;  position:absolute; visibility:hidden\">");  
  12. for (var h = 10; h >= 1; h--) {  
  13.     str += "<div onmouseover=\"this.style.backgroundColor='#BDEBEE';\" onmouseout=\"this.style.backgroundColor='#E3E3E3';\" onclick=\"_select(this)\" style='cursor:hand;border:1px solid #ccc; border-collapse:collapse;width:25px;text-align:center;font-size:12px;height:25px;padding-top:6px;float:left;margin-right:4px;margin-top:4px;'>" + h + "</div>";  
  14.     str += "<div onmouseover=\"this.style.backgroundColor='#BDEBEE';\" onmouseout=\"this.style.backgroundColor='#E3E3E3';\"  onclick=\"_select(this)\" style='cursor:hand;border:1px solid #ccc; border-collapse:collapse;width:25px;text-align:center;font-size:12px;height:25px;padding-top:6px;float:left;margin-right:4px;margin-top:4px;'>" + (h - 0.5) + "</div>";  
  15. }  
  16.   
  17. str += "</div>";  
  18. document.writeln(str);  
  19. var _fieldname;  
  20. function _SetAgio(tt) {  
  21.     _fieldname = tt;  
  22.     var ttop = tt.offsetTop;    //TT控件的定位点高  
  23.     var thei = tt.clientHeight;    //TT控件本身的高  
  24.     var tleft = tt.offsetLeft;    //TT控件的定位点宽  
  25.     while (tt = tt.offsetParent) {  
  26.         ttop += tt.offsetTop;  
  27.         tleft += tt.offsetLeft;  
  28.     }  
  29.     document.all._contents.style.top = ttop + thei + 4;  
  30.     document.all._contents.style.left = tleft;  
  31.     document.all._contents.style.visibility = "visible";  
  32. }  
  33. function _select(obj) {  
  34.     _fieldname.value = obj.innerHTML/10;  
  35.     document.all._contents.style.visibility = "hidden";  
  36. }  
0 0