webview_search.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"/>
  6. <meta name="HandheldFriendly" content="true"/>
  7. <meta name="MobileOptimized" content="320"/>
  8. <title>TitleNView Search</title>
  9. <script type="text/javascript" src="../js/common.js"></script>
  10. <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
  11. <script>
  12. var ws = null;
  13. // H5 plus事件处理
  14. function plusReady(){
  15. ws = plus.webview.currentWebview();
  16. ws.addEventListener('titleNViewSearchInputChanged', function(e){
  17. console.log('titleNViewSearchInputChanged: '+JSON.stringify(e));
  18. }, false);
  19. ws.addEventListener('titleNViewSearchInputConfirmed', function(e){
  20. console.log('titleNViewSearchInputConfirmed: '+JSON.stringify(e));
  21. });
  22. ws.addEventListener('titleNViewSearchInputClicked', function(e){
  23. clickedSearch();
  24. }, false);
  25. }
  26. document.addEventListener('plusready', plusReady, false);
  27. // 更新按钮文字
  28. var bSwitch = false;
  29. function changeButton() {
  30. var t = bSwitch?'呼和浩特市':'北京市';
  31. bSwitch = !bSwitch;
  32. ws.setTitleNViewButtonStyle(1, {text:t});
  33. }
  34. // 更新提示文本
  35. var bHolder = false;
  36. function changePlaceholder() {
  37. var t = bHolder?'点击搜索':'修改后的提示文本';
  38. bHolder = !bHolder;
  39. ws.setStyle({titleNView:{searchInput:{
  40. placeholder: t
  41. }}});
  42. }
  43. function getPlaceholder() {
  44. var s = ws.getStyle();
  45. var p = (s.titleNView&&s.titleNView.searchInput&&s.titleNView.searchInput.placeholder)||'没有设置placeholder';
  46. plus.nativeUI.toast(p);
  47. }
  48. // 更新搜索文本
  49. var bText = false;
  50. function changeText() {
  51. var t = bText?'':'输入文本';
  52. bText = !bText;
  53. ws.setTitleNViewSearchInputText(t);
  54. }
  55. // 打开搜索界面
  56. var wsearch = null;
  57. function clickedSearch(){
  58. if(wsearch){ // 避免快速点击打开
  59. return;
  60. }
  61. wsearch = plus.webview.create('webview_searchInput.html', 'searchinput', {
  62. scrollIndicator: 'none',
  63. backButtonAutoControl: 'close',
  64. titleNView: {
  65. autoBackButton: false,
  66. 'padding': '5px',
  67. backgroundColor: '#D74B28',
  68. buttons: [{
  69. text: '取消',
  70. color: '#00CCCC',
  71. fontSize: '16px',
  72. width: '50px',
  73. onclick: 'javascript:plus.webview.currentWebview().close("none")'
  74. }],
  75. searchInput: {
  76. align: 'left',
  77. backgroundColor: '#EEEEEE',
  78. borderRadius: '15px',
  79. placeholder: '点击搜索',
  80. placeholderColor: '#FF0000',
  81. autoFocus: true
  82. }
  83. }
  84. });
  85. wsearch.addEventListener('close', function(){
  86. wsearch = null;
  87. }, false);
  88. wsearch.show('fade-in', 300);
  89. }
  90. // 点击按钮
  91. function clickedButton(){
  92. plus.nativeUI.toast('clicked button!');
  93. console.log('clicked button!');
  94. }
  95. </script>
  96. </head>
  97. <body>
  98. <div style="display:flex;">
  99. <div style="background-color: #CC0000;width:25%;height:200px;"></div>
  100. <div style="background-color: #00CC00;width:25%;height:200px;"></div>
  101. <div style="background-color: #0000CC;width:25%;height:200px;"></div>
  102. <div style="background-color: #ff8800;width:25%;height:200px;"></div>
  103. </div>
  104. <br/>
  105. <br/>
  106. <p>原生标题栏titleNView搜索框示例</p>
  107. <br/>
  108. <div class="button" onclick="changeButton()">修改标题栏按钮文本</div>
  109. <div class="button" onclick="changePlaceholder()">修改搜索提示placeholder</div>
  110. <div class="button" onclick="getPlaceholder()">获取搜索提示placeholder</div>
  111. <div class="button" onclick="changeText()">修改搜索文本</div>
  112. <br/>
  113. <div style="width:100%;height:1000px"></div>
  114. </body>
  115. </html>