首页 新闻 搜索 专区 学院

javascript 求高手看看这段代码我哪里写错了?

0
悬赏园豆:15 [已解决问题] 解决于 2015-05-25 09:33

基础较差,没找出来。调试也没弄明白。

 1 function GetValue(para) {  
 2      var reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");  
 3      var r = this.substr(this.indexOf("\?")+1).match(reg);  
 4   if (r!=null) 
 5      return unescape(r[2]); 
 6     return null;  
 7  }  
 8     var str = "http://localhost:8080/ArcGIS/mapviewer.jsf?width=1059&height=523&TextString=1B024";
 9      //如果获取本页地址用var str = location.href;    
10  //  alert(str.GetValue("TextString"));
11   var value=str.GetValue("TextString"); 
12   
13 String.prototype.qt = function(query){
14 var queryTask = new QueryTask("http://192.168.0.95:6080/ArcGIS/rest/services/SH001DangRuan1/MapServer");
15 var query = new Query();
16     query.where = "TextString='value'";
17     query.returnGeometry = true;
18    query.outFields=["*"];
19     query.execute(query,handleQueryResults);
20 }
21    
22     String.prototype. handleQueryResults= function(results) {
23        var symbol = new esri.symbol.SimpeFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,0,255,0.35]), 1),new dojo.Color([125,125,125,0.35]));
24           };
25    adfdojo.addOnload(qt);
谁说不可以重名的主页 谁说不可以重名 | 初学一级 | 园豆:15
提问于:2015-05-21 15:53
< >
分享
最佳答案
0

这段代码想干啥,报什么错?

收获园豆:15
火悬崖 | 菜鸟二级 |园豆:434 | 2015-05-21 16:04

没报错  就是不显示效果

先 获取URL参数

然后 在地图上查询这个参数,显示效果

谁说不可以重名 | 园豆:15 (初学一级) | 2015-05-21 16:06

@谁说不可以重名: HTML代码也贴过来,我调试一下看看。

火悬崖 | 园豆:434 (菜鸟二级) | 2015-05-21 16:09

@火悬崖: 

 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 2 
 3 <html>
 4   <head>
 5     <title>ArcGIS</title>
 6 
 7     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 8     
 9     <link rel="stylesheet" href="css/soria.all.css.min.css" type="text/css"></link>
10     <link rel="stylesheet" href="css/adf.css" type="text/css"></link>
11     <link rel="stylesheet" href="css/wma.css" type="text/css"></link>
12     <link rel="stylesheet" href="css/themes/light-blue/light-blue.css" type="text/css"></link>  
13     
14     <script type="text/javascript" src="js/esri/dojo/dojo.js"></script>
15   
16   </head>
17   <body>
18     <table style="width:100%; height:100%;">
19       <tbody>
20         <tr>
21           <td align="center" id="loading">
22             <img src="images/loading.gif" alt="Loading..." title="Loading..."/>
23           </td>
24         </tr>
25       </tbody>
26     </table>
27     <script type="text/javascript">
28       adfdojo.addOnLoad( function() {
29         var url = "mapviewer.jsf";
30         try {
31           var b = adfdojo.contentBox(adfdojo.body());
32           url +="?TextString=" + '1B024' + "&width=" + (b.w - 307) + "&height=" + (b.h - 80)  ;
33         }
34         catch (exception) {
35           console.error("Unable to determine dimensions of body element.");
36         }
37 
38         window.location.href = url;
39       });
40     </script>
41   </body>
42 </html>

 

  1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2 
  3 <%@page contentType="text/html" pageEncoding="UTF-8" %>
  4 
  5 <%@taglib uri="http://www.esri.com/adf/web" prefix="a"%>
  6 <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
  7 <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
  8 <%@ page language="java" import="java.util.Locale" %>
  9 
 10 <html>
 11   <head>
 12   
 13     <meta http-equiv="Content-type" content="text/html;charset=UTF-8" > 
 14     
 15     <title>Web Mapping Application</title>
 16     
 17     <link rel="stylesheet" href="css/soria.all.css.min.css" type="text/css"></link>
 18     <link rel="stylesheet" href="css/adf.css" type="text/css"></link>
 19     <link rel="stylesheet" href="css/wma.css" type="text/css"></link>
 20     <link rel="stylesheet" href="css/themes/blue2/blue2.css" type="text/css"></link>  
 21     
 22     <script type="text/javascript" language="javascript" src="js/esri/dojo/dojo.js" djConfig="locale:'<%=Locale.getDefault().toString().replace('_', '-').toLowerCase()%>' "></script>
 23     <script type="text/javascript">
 24     
 25       adfdojo.require("adf.adf");
 26       adfdojo.require("wma.app");
 27       adfdojo.requireLocalization("resource","adf");
 28       adfdojo.requireLocalization("resource","wma");
 29       
 30       adfdojo.addOnLoad(function() {
 31         if (wma) {
 32           wma.init();
 33         }
 34       });
 35 </script>
 36  <script type="text/javascript">
 37 
 38    String.prototype.GetValue= function(para) {  
 39      var reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");  
 40      var r = this.substr(this.indexOf("\?")+1).match(reg);  
 41   if (r!=null) 
 42      return unescape(r[2]); 
 43     return null;  
 44  }  
 45     var str = "http://localhost:8080/ArcGIS/mapviewer.jsf?width=1059&height=523&TextString=1B024";
 46      //如果获取本页地址用var str = location.href;    
 47     //alert(str.GetValue("TextString"));
 48    var value=str.GetValue("TextString"); 
 49     
 50 //    String.prototype.qt = function(query){
 51 //var queryTask = new QueryTask("http://192.168.0.95:6080/ArcGIS/rest/services/SH001DangRuan1/MapServer");
 52 //var query = new Query();
 53 //    query.where = "TextString='str.GetValue("TextString")'";
 54 //    query.returnGeometry = true;
 55 //    query.outFields=["*"];
 56 //    query.execute(query,handleQueryResults);
 57 //}
 58    
 59 //    String.prototype. handleQueryResults= function(results) {
 60 //       var symbol = new esri.symbol.SimpeFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,0,255,0.35]), 1),new dojo.Color([125,125,125,0.35]));
 61 //          };
 62 //   adfdojo.addOnload(qt);
 63    </script>
 64 
 65   </head>
 66 
 67   <f:view>
 68     <f:loadBundle basename="res.mapviewer" var="res"/>
 69     
 70     <a:context value="#{mapContext}" />
 71     
 72     <body class="soria" >
 73       <h:form id="mapForm" style="height: 100%; width: 100%;">
 74       
 75         <div id="layoutContainer">
 76           
 77         </div>
 78         
 79         <div id="content">
 80           
 81           <span id="titleText"></span>
 82           
 83           <div id="linksPane">
 84             <table align="right">
 85                 <tr>
 86                   <td align="right">
 87                     <a class="appLink" href="help/index.html" target="_blank">Help</a>
 88                   </td>
 89                 </tr>
 90 
 91                 <tr>
 92                   <td align="right">
 93                     <h:outputText styleClass="appNote" value="#{res.LoggedInAs}: #{webappSecurityInfo.user}" rendered="#{webappSecurityInfo.secured}"/>
 94                     <h:commandLink styleClass="appLink" action="#{webappSecurityInfo.logOut}" rendered="#{webappSecurityInfo.logoutAvailable}">
 95                        <h:outputText value=" #{res.LogOut}"/>
 96                     </h:commandLink>
 97                   </td>
 98                 </tr>
 99               </table> 
100           </div> 
101         
102           <!-- 
103               Custom content to place in a dijit.TitlePane should be placed here in a div whose class attribute is "sideContent".
104               The title attribute for this node will be used as the title.  If a resource string wma.Res.getString("<title attribute value>")
105               exists, the corresponding value will be used first.
106               
107               For Example:              
108               <div class="sideContent" title="Content Title String">
109                 <h1>Custom Side Content</h1>
110               </div>
111           -->
112           
113           <!-- Map Control Content -->
114           <a:map value="#{mapContext.webMap}" id="map1" width="#{param.width}" height="#{param.height}" scaleBar="#{mapContext.attributes['webappScaleBar']}" />
115 <div id="northarrow">
116     <h:inputHidden id="northarrowHid" value="#{mapContext.attributes.webappNorthArrow.imageUrl}" />
117 </div>
118 
119           
120           <!-- Map TOC Content -->
121           <a:toc id="toc1" value="#{mapContext.webToc}" mapId="map1" clientPostBack="true" />
122           
123           <!-- Task Results TOC Content -->
124           <a:results id="results" value="#{mapContext.attributes.webappResults}" mapId="map1" clientPostBack="true" xslFile="results.xsl" />
125   
126           <!-- Map Overview Content -->
127           <a:overview id="ov1" value="#{mapContext.webOverview}" mapId="map1" width="200" height="150" lineColor="#F00" />
128           
129           <!-- Map Tools Content -->
130           <a:task id="mapToolsTask"
131                   value="#{mapContext.attributes.webappMapToolsTask}"
132                   taskInfo="#{mapContext.attributes.webappMapToolsTask.taskInfo}"
133                   mapId="map1" 
134                   windowingSupport="false"
135                   style="padding:0px;margin:0px;" 
136                   xslFile="maptoolstask.xsl" />
137           <input id="overviewToggleButton" width="25px" type="image" height="25px" 
138                  title="Toggle Overview Map"
139                  onclick="wma.toggleOverview(this); return false;"
140                  onload="adf.Utils.onHandleImage(this, 'images/hide-overview-map.png');"
141                  src="images/hide-overview-map.png" />
142             
143           <!--  Application Tasks Content -->
144           <div id="task-menu" class="tasks-menu">
145             <ul>
146               <li class="menu-bar">
147                 <a href="#" class="menu-header" title="Search Attributes Task" onclick="wma.toggleWindow('win_EsriTaskCell_searchAttributesTask');">
148                   <span>Search Attributes</span>
149                 </a>
150               </li>
151             </ul>
152           </div>
153 
154           <a:task id="searchAttributesTask" value="#{mapContext.attributes.webappSearchAttributesTask}" taskInfo="#{mapContext.attributes.webappSearchAttributesTask.taskInfo}" mapId="map1" />
155 
156           <h:inputHidden id="taskWindows"/>
157         </div>
158       </h:form>
159     </body>
160   </f:view>
161 </html>
谁说不可以重名 | 园豆:15 (初学一级) | 2015-05-21 16:12

@火悬崖: js怎么调试? 一直没弄明白

谁说不可以重名 | 园豆:15 (初学一级) | 2015-05-21 16:17

@谁说不可以重名: 

 

adfdojo是什么?

还有你的代码我粘贴过来怎么还有前面的序号。。。

火悬崖 | 园豆:434 (菜鸟二级) | 2015-05-21 16:19

@火悬崖: 额 我忘记了 这个是ADF框架自动生成的文件,  我只是加了JS

谁说不可以重名 | 园豆:15 (初学一级) | 2015-05-21 16:23

@谁说不可以重名: 额,ADF没有过,不知道能不能像你这样用,我调试它直接报 未定义错误,你可以用firebug(火狐)或者IE自带的开发人员工具自己调试看看。

火悬崖 | 园豆:434 (菜鸟二级) | 2015-05-21 16:26

@火悬崖: adfdojo明显是dojo库里定义的对象。

xmodygetz | 园豆:575 (小虾三级) | 2015-05-21 16:28

@xmodygetz: 额,不好意思,没有过这个库,你可以帮他看看怎么解决问题。

火悬崖 | 园豆:434 (菜鸟二级) | 2015-05-21 16:30

@火悬崖: 我只是听说过,没用过。但是我看了他的代码,不明白为什么他要设定String的原型,是不是可以打印一下qt的具体值看看。

xmodygetz | 园豆:575 (小虾三级) | 2015-05-21 16:42

虽然问题没有解决,不过还是感谢

谁说不可以重名 | 园豆:15 (初学一级) | 2015-05-25 09:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册