多语言简单科学计算器插件

  • 源码大小:69.42KB
  • 所需积分:1积分
  • 源码编号:19JP-3555
  • 浏览次数:602次
  • 最后更新:2023年06月26日
  • 所属栏目:其他
本站默认解压密码:19jp.com 或 19jp_com

简介

一个jQuery插件,它在焦点上的输入字段中弹出一个简单或科学的计算器。单击计算器上的USE按钮将把当前值插入到您的输入字段中。

它还包含15个本地化,您可以在其他主要语言的网站上使用此插件。

参见:

  • JavaScript中的10个最佳在线计算器应用程序

如何使用它:

1.包括最新的jQuery库和jQuery.cacalculator.js库。

  1. <!-- Core -->
  2. <script src="/path/to/cdn/jquery.slim.min.js"></script>
  3. <script src="/path/to/jquery.plugin.js"></script>
  4. <script src="/path/to/jquery.calculator.js"></script>
  5.  
  6. <!-- Locals -->
  7. <script src="/path/to/jquery.calculator-ca.js"></script>
  8. <script src="/path/to/jquery.calculator-da.js"></script>
  9. <script src="/path/to/jquery.calculator-de.js"></script>
  10. <script src="/path/to/jquery.calculator-es.js"></script>
  11. <script src="/path/to/jquery.calculator-fr.js"></script>
  12. <script src="/path/to/jquery.calculator-hr.js"></script>
  13. <script src="/path/to/jquery.calculator-it.js"></script>
  14. <script src="/path/to/jquery.calculator-ms.js"></script>
  15. <script src="/path/to/jquery.calculator-nl.js"></script>
  16. <script src="/path/to/jquery.calculator-no.js"></script>
  17. <script src="/path/to/jquery.calculator-pl.js"></script>
  18. <script src="/path/to/jquery.calculator-pt-BR.js"></script>
  19. <script src="/path/to/jquery.calculator-ru.js"></script>
  20. <script src="/path/to/jquery.calculator-sl.js"></script>
  21. <script src="/path/to/jquery.calculator-sr.js"></script>
  22. <script src="/path/to/jquery.calculator-tr.js"></script>
  23. <script src="/path/to/jquery.calculator-uk.js"></script>
  24. <script src="/path/to/jquery.calculator-zh-CN.js"></script>
  25. <script src="/path/to/jquery.calculator-zh-TW.js"></script>

2.包括必要的样式表。

  1. <link rel="stylesheet" href="jquery.calculator.css" />
  2. <!-- OR -->
  3. <link rel="stylesheet" href="jquery.calculator.alt.css" />

3.调用插件并将计算器附加到输入字段。

  1. <input type="text" id="myCalculator">
  1. // basic calculator
  2. $('#myCalculator').calculator({
  3. // options here
  4. });
  5.  
  6. // scientific Calculator
  7. $('#myCalculator').calculator({
  8. layout: $.calculator.scientificLayout
  9. // more options here
  10. });

4.所有插件选项。

  1. $('#myCalculator').calculator({
  2.  
  3. // 'focus' for popup on focus, 'button' for trigger button,
  4. // 'both' for either
  5. // 'operator' for non-numeric character entered,
  6. // 'opbutton' for operator/button combination.
  7. showOn: 'focus',
  8.  
  9. // The URL for the trigger button image
  10. buttonImage: '',
  11.  
  12. // True if the image appears alone
  13. buttonImageOnly: false,
  14.  
  15. // Call back function to determine if a keystroke opens the calculator
  16. isOperator: null,
  17.  
  18. // The name of jQuery animation for popup
  19. showAnim: 'show',
  20.  
  21. // Animation options.
  22. showOptions: {},
  23.  
  24. // Duration in ms
  25. duration: 'normal',
  26.  
  27. // Append text to the input
  28. appendText: '',
  29.  
  30. // Use jQuery UI Themeroller
  31. useThemeRoller: false,
  32.  
  33. // Additional CSS class(es)
  34. calculatorClass: '',
  35.  
  36. // Shows formula
  37. showFormula: false,
  38.  
  39. // Text across the top of the calculator
  40. prompt: '',
  41.  
  42. // ' BSCECA', '[email protected]', '[email protected]', '_7_8_9_*@E', '_0_._=_/'
  43. layout: layoutStandard,
  44.  
  45. // The initial value
  46. value: 0,
  47.  
  48. // The numeric base
  49. base: 10,
  50.  
  51. // The number of digits of precision
  52. precision: 10,
  53.  
  54. // Save memory into cookie
  55. memoryAsCookie: false,
  56. cookieName: 'calculatorMemory',
  57. cookieExpires: 24 * 60 * 60,
  58. cookiePath: '',
  59.  
  60. // Use degress for trigonometric functions
  61. useDegrees: false,
  62.  
  63. // Restrict characters to numerics
  64. constrainInput: true,
  65.  
  66. // callback functions
  67. onOpen: function(value, inst) {
  68. // do something
  69. },
  70.  
  71. onButton: function(label, value, inst) {
  72. // do something
  73. },
  74.  
  75. onClose: function(value, inst) {
  76. // do something
  77. },
  78.  
  79. });

4.API方法

  1. // update options
  2. $.calculator.setDefaults(settings)
  3.  
  4. // add or update the definition for a key to appear on the calculator
  5. // code (string) is the two-character code that identifies this key and can be used within a layout to denote its position. Use lower-case characters for your names to avoid conflicts with the standard keys.
  6.  
  7. // label (string) is the display text that appears on the button for this key. If prefixed by a hash (#) the rest of the label is used to look up the actual text in the regional settings. For example, '#erase' looks for an 'eraseText' setting for the button text and an 'eraseStatus' setting for a popup tool-tip.
  8. // type (enumerated) denotes the type of key and must be one of the defined constants ($.calculator.): digit for digits that make up a number, binary for binary operators (need two values), unary for unary operators (only need one value), control for special control buttons, or space for empty space between buttons.
  9. // func (function) is the function to call when this key is activated. The function accepts a single parameter, being the instance settings for the calculator, and should update its state via the curValue and prevValue (for binary operations) fields. See examples on the key definitions page.
  10. // style (string) is a space-separated list of CSS styles to apply to this button. Each style is prefixed by 'calculator-' when applied.
  11. // constant (string) is the name of a constant (within $.calculator) that can be used instead of the code to position a key within a layout.
  12. // keystroke (char or number) is the character or keycode that maps onto this button for keyboard-driven calculations.
  13. // keyName (string, optional) is the name of the keystroke above (up to three characters) that is shown when the Alt is held down. This value is not needed if the keystroke is a standard character.
  14. $.calculator.addKeyDef( code, label, type, func, style, constant, keystroke, keyName)
  15.  
  16. // update options
  17. $(selector).calculator('option', options)
  18. // or
  19. $(selector).calculator('option', name, value)
  20.  
  21. // get option value
  22. $(selector).calculator('option', name)
  23.  
  24. // destroy
  25. $('selector').calculator('destroy')
  26.  
  27. // show
  28. $('selector').calculator('show')
  29.  
  30. // hide
  31. $('selector').calculator('hide')
  32.  
  33. // enable
  34. $('selector').calculator('enable')
  35.  
  36. // disable
  37. $('selector').calculator('disable')
  38.  
  39. // check if is disabled
  40. $('selector').calculator('isDisabled')

更新日志:

2022-05-28

  • 更新的演示和文档

v2.0.1版本(2014-06-21)

  • 更新到最新版本。

v2.0.0版本(2014-01-19)

  • 更新到最新版本。

预览截图