clearicon.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>TextBox with Clear Icon - jQuery EasyUI Demo</title>
  6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
  7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
  8. <link rel="stylesheet" type="text/css" href="../demo.css">
  9. <script type="text/javascript" src="../../jquery.min.js"></script>
  10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>TextBox with Clear Icon</h2>
  14. <p>This example shows how to create an textbox with an icon to clear the input element itself.</p>
  15. <div style="margin:20px 0 40px 0;"></div>
  16. <div class="easyui-panel" style="width:100%;max-width:400px;padding:30px 60px;">
  17. <div style="margin-bottom:20px">
  18. <input id="tt" style="width:100%;" data-options="
  19. label: 'Email:',
  20. labelPosition: 'top',
  21. prompt: 'Input something here!',
  22. value: 'my@email.com',
  23. icons:[{
  24. iconCls:'icon-search',
  25. handler: function(e){
  26. var v = $(e.data.target).textbox('getValue');
  27. alert('The inputed value is ' + (v ? v : 'empty'));
  28. }
  29. }]
  30. ">
  31. </div>
  32. </div>
  33. <script>
  34. $.extend($.fn.textbox.methods, {
  35. addClearBtn: function(jq, iconCls){
  36. return jq.each(function(){
  37. var t = $(this);
  38. var opts = t.textbox('options');
  39. opts.icons = opts.icons || [];
  40. opts.icons.unshift({
  41. iconCls: iconCls,
  42. handler: function(e){
  43. $(e.data.target).textbox('clear').textbox('textbox').focus();
  44. $(this).css('visibility','hidden');
  45. }
  46. });
  47. t.textbox();
  48. if (!t.textbox('getText')){
  49. t.textbox('getIcon',0).css('visibility','hidden');
  50. }
  51. t.textbox('textbox').bind('keyup', function(){
  52. var icon = t.textbox('getIcon',0);
  53. if ($(this).val()){
  54. icon.css('visibility','visible');
  55. } else {
  56. icon.css('visibility','hidden');
  57. }
  58. });
  59. });
  60. }
  61. });
  62. $(function(){
  63. $('#tt').textbox().textbox('addClearBtn', 'icon-clear');
  64. });
  65. </script>
  66. </body>
  67. </html>