clearicon.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. <input id="tt" style="width:400px" data-options="
  17. prompt: 'Input something here!',
  18. icons:[{
  19. iconCls:'icon-search',
  20. handler: function(e){
  21. var v = $(e.data.target).textbox('getValue');
  22. alert('The inputed value is ' + (v ? v : 'empty'));
  23. }
  24. }]
  25. ">
  26. <script>
  27. $.extend($.fn.textbox.methods, {
  28. addClearBtn: function(jq, iconCls){
  29. return jq.each(function(){
  30. var t = $(this);
  31. var opts = t.textbox('options');
  32. opts.icons = opts.icons || [];
  33. opts.icons.unshift({
  34. iconCls: iconCls,
  35. handler: function(e){
  36. $(e.data.target).textbox('clear').textbox('textbox').focus();
  37. $(this).css('visibility','hidden');
  38. }
  39. });
  40. t.textbox();
  41. if (!t.textbox('getText')){
  42. t.textbox('getIcon',0).css('visibility','hidden');
  43. }
  44. t.textbox('textbox').bind('keyup', function(){
  45. var icon = t.textbox('getIcon',0);
  46. if ($(this).val()){
  47. icon.css('visibility','visible');
  48. } else {
  49. icon.css('visibility','hidden');
  50. }
  51. });
  52. });
  53. }
  54. });
  55. $(function(){
  56. $('#tt').textbox().textbox('addClearBtn', 'icon-clear');
  57. });
  58. </script>
  59. </body>
  60. </html>