newsAdd.jsp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <form id="addNewsForm" method="post">
  4. <table class="mytable" style="width: 100%;">
  5. <tr>
  6. <th width="15%">标题</th>
  7. <td width="85%" colspan="3" >
  8. <input class="easyui-validatebox" required="true" type="text" id="title_add" name="news.title" style="width:545px">
  9. </td>
  10. </tr>
  11. <tr>
  12. <th>栏目类型</th>
  13. <td colspan="3">
  14. <select id="newsType_add" name="news.newsType" style="width:173px;">
  15. <option value="">请选择...</option>
  16. </select>
  17. </td>
  18. </tr>
  19. <tr>
  20. <th>发布人</th>
  21. <td>
  22. <input class="easyui-validatebox" required="true" type="text" id="operator_add" name="news.operator" value="${user.fullName}">
  23. </td>
  24. <th>发布时间</th>
  25. <td>
  26. <input class="easyui-datebox" required="true" type="text" id="businessTime_add" name="news.businessTime">
  27. </td>
  28. </tr>
  29. <tr>
  30. <th>图片新闻设置</th>
  31. <td colspan="3">
  32. 选取第<input type="text" id="dz" name="news.num" style="width:40px;"/> 张图片作为图片新闻展示
  33. <input type="Button" value="提取" width="150px" onclick="ce()" style="margin:5px 0px 5px 0px;"/>
  34. <br>
  35. <input type="text" id="imagePath_add" name="news.imagePath" style="width:545px;margin:5px 0px 5px 0px;">
  36. </td>
  37. </tr>
  38. <tr>
  39. <th>新闻内容</th>
  40. <td colspan="3">
  41. <textarea id="editor_content" name="news.content" rows="20" cols="100" style="width: 95%; height: 400px;"></textarea>
  42. </td>
  43. </tr>
  44. <tr>
  45. <th>备注</th>
  46. <td colspan="3">
  47. <textarea rows="4" cols="80" name="news.remark" style="width:95%"></textarea>
  48. </td>
  49. </tr>
  50. </table>
  51. </form>
  52. <script type="text/javascript">
  53. KindEditor.ready(function(K) {
  54. var options = {
  55. //自定义工具栏
  56. items : [ 'source', 'plainpaste', 'wordpaste', 'preview', '|',
  57. 'fontname', 'fontsize', '|',
  58. 'forecolor', 'hilitecolor', 'bold',
  59. 'italic', 'underline', 'removeformat', '|',
  60. 'clearhtml', 'selectall','|',
  61. 'justifyleft', 'justifycenter', 'justifyright',
  62. 'indent','outdent','insertorderedlist', 'insertunorderedlist', '|',
  63. 'image', "multiimage", 'insertfile', '|',
  64. 'table', 'baidumap' ],
  65. //图片上传Action
  66. uploadJson : whzl.basePath+'/imgUpload_imgUpload',
  67. //允许网络图片上传
  68. allowImageRemote : true,
  69. //文件空间Action
  70. fileManagerJson : whzl.basePath+'/fileManager_fileManager',
  71. //允许展示文件空间
  72. allowFileManager : true,
  73. //kindeditor创建后,将编辑器的内容设置到原来的textarea控件里
  74. afterCreate : function(){ this.sync(); },
  75. //编辑器聚焦后,将编辑器的内容设置到原来的textarea控件里
  76. afterBlur: function(){ this.sync(); },
  77. //编辑器内容发生变化后,将编辑器的内容设置到原来的textarea控件里
  78. afterChange: function(){ this.sync(); }
  79. };
  80. editor = K.create('#editor_content', options);
  81. });
  82. function ce(){
  83. //indexOf某个指定的字符串值在字符串中首次出现的位置
  84. if (editor.html().toLowerCase().indexOf("<img") == -1 && editor.html().toLowerCase().indexOf("src=")) {
  85. alert("您设置了把内容中第一条图片设置为图片地址\n但内容中并没有图片");
  86. return false;
  87. }else{
  88. //图片正则
  89. var reg=/<img.+?src=('|")?([^'"]+)('|")?(?:\s+|>)/gim;
  90. var arr = [];
  91. while(tem=reg.exec(editor.html()))
  92. {
  93. arr.push(tem[2]);
  94. }
  95. var imgIndex = $("#dz").val();
  96. if(imgIndex != ""){
  97. if(!isNaN(imgIndex)){
  98. var z = imgIndex.trim();
  99. if(z > arr.length || z <= 0){
  100. alert("内容中没有你要提取的图片!");
  101. return;
  102. }else{
  103. for(var i=1; i <= arr.length; i++){
  104. if(i == z){
  105. alert("提取成功!");
  106. $("#imagePath_add").val(arr[i-1]);
  107. }
  108. }
  109. }
  110. }else{
  111. alert("请输入数字!");
  112. }
  113. }else{
  114. alert("请选择提取的图片!");
  115. }
  116. }
  117. }
  118. </script>