Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]wynik z js w polu input
maksik
post
Post #1





Grupa: Zarejestrowani
Postów: 206
Pomógł: 0
Dołączył: 26.09.2012

Ostrzeżenie: (0%)
-----


Witam
mam taki javascript
  1. <script>$("#miasto").html(geoip_city());</script>


jednakże nie wyświetla mi się on w polu input, a tylko w zwyklym divie. Co z nim jest nie poprawnie?
  1. <input type="text" id="miasto" name="miasto">
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
maksik
post
Post #2





Grupa: Zarejestrowani
Postów: 206
Pomógł: 0
Dołączył: 26.09.2012

Ostrzeżenie: (0%)
-----


  1. <script src="http://j.maxmind.com/app/geoip.js"></script>
  2. <script type="text/javascript">
  3.  
  4. var MeOnTheMap = function(options){
  5.  
  6. this.options = {
  7. address : "",
  8. container : "",
  9. defaultUI : true,
  10. noDragging : false,
  11. html : "",
  12. zoomLevel : 16,
  13. view : 0
  14. };
  15.  
  16. this.preloads = [];
  17.  
  18. this.initialize = function(options) {
  19.  
  20. for (var opt in options){
  21. this.options[opt] = options[opt];
  22. }
  23.  
  24. this.preparePreloading();
  25.  
  26. this.container = document.getElementById(this.options.container);
  27. if (!this.container) {
  28. alert("Could not locate \"" + this.options.container + "\"");
  29. return;
  30. }
  31.  
  32. this.findLocation();
  33. };
  34.  
  35. this.preparePreloading = function(){
  36. var regxp = new RegExp('(src)=("[^"]*")','g');
  37. var sources = this.options.html.match(regxp);
  38.  
  39. if (!sources)
  40. return;
  41.  
  42. function getHandler(obj) {
  43. return function(){
  44. var el = document.getElementById(obj.id);
  45. if (el){
  46. el.parentNode.replaceChild(this, el);
  47. obj.marker.tooltip.redraw(true);
  48. }
  49. };
  50. };
  51.  
  52. for (var i = 0; i < sources.length; i++){
  53. this.options.html = this.options.html.replace(sources[i],"style=\"visibility:visible\" id=\"preloadimg" + i + "\" src=\"\"");
  54.  
  55. var src = sources[0].split("=\"")[1];
  56. src = src.substring(0,src.length - 1);
  57.  
  58. var img = new Image();
  59.  
  60. this.preloads.push({
  61. element: img,
  62. src: src,
  63. id: "preloadimg" + i
  64. });
  65.  
  66. img.onload = getHandler(this.preloads[this.preloads.length - 1]);
  67. }
  68. };
  69.  
  70. this.startPreloading = function(marker, map){
  71. for (var i = 0; i < this.preloads.length; i++) {
  72. this.preloads[i].marker = marker;
  73. this.preloads[i].map = map;
  74. this.preloads[i].element.src = this.preloads[i].src;
  75. }
  76. };
  77.  
  78. this.findLocation = function() {
  79. var _this = this;
  80. this.geoLocator = new GClientGeocoder();
  81. this.geoLocator.getLatLng(this.options.address, function(response){
  82. _this.handleGetLocatorResponse(response);
  83. });
  84. };
  85.  
  86. this.getIcon = function() {
  87. var icon = new GIcon(G_DEFAULT_ICON);
  88. icon.image = "images/icon.png";
  89. icon.shadow = "images/shadow.png";
  90. icon.iconSize = new GSize(35,35);
  91. icon.shadowSize = new GSize(52, 35);
  92. icon.iconAnchor = new GPoint(17, 35);
  93. return icon;
  94. };
  95.  
  96. this.handleGetLocatorResponse = function(response){
  97. this.geoLocator = null;
  98.  
  99. if(!response) {
  100. alert("Could not resolve this addess \"" + this.options.address + "\"");
  101. return;
  102. }
  103.  
  104. var type = "";
  105. switch (this.options.view) {
  106. case 1 : type = G_SATELLITE_MAP; break;
  107. case 2 : type = G_HYBRID_MAP; break;
  108. default : type = G_NORMAL_MAP; break;
  109. }
  110.  
  111. this.map = new GMap2(this.container);
  112. this.map.setMapType(type);
  113. this.map.setCenter(response, this.options.zoomLevel);
  114. this.map.disableScrollWheelZoom();
  115.  
  116. if (this.options.noDragging)
  117. this.map.disableDragging();
  118.  
  119. if (this.options.defaultUI)
  120. this.map.setUIToDefault();
  121.  
  122. this.marker = new GMarker(response,{icon: this.getIcon()});
  123. this.map.addOverlay(this.marker);
  124.  
  125. if (!this.options.html || this.options.html == "")
  126. return;
  127.  
  128. this.marker.tooltip = new Tooltip(this.marker, this.options.html);
  129. this.map.addOverlay(this.marker.tooltip);
  130. this.marker.tooltip.show();
  131.  
  132. if (this.newCenter) {
  133. var markerPos = this.map.fromLatLngToDivPixel(this.marker.getPoint());
  134. var pos = this.map.fromContainerPixelToLatLng({
  135. x: markerPos.x + this.newCenter.x,
  136. y: markerPos.y + this.newCenter.y
  137. });
  138. this.map.setCenter(pos);
  139. }
  140.  
  141. this.startPreloading(this.marker, this.map);
  142. };
  143.  
  144. this.adjustMapCenter = function(position){
  145. if (!this.geoLocator && this.map){
  146. var markerPos = this.map.fromLatLngToDivPixel(this.marker.getPoint());
  147. var pos = this.map.fromContainerPixelToLatLng({
  148. x: markerPos.x + position.x,
  149. y: markerPos.y + position.y
  150. });
  151. this.map.setCenter(pos);
  152. } else {
  153. this.newCenter = position;
  154. }
  155. };
  156.  
  157. this.initialize(options);
  158. };
  159.  
  160. function Tooltip(marker, text){
  161.  
  162. this.isIE6 = function(){
  163. if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
  164. var ieversion = new Number(RegExp.$1);
  165. return (ieversion == 6);
  166. }
  167. return false;
  168. };
  169.  
  170. this.initialize = function(map){
  171. this.map = map;
  172. this.div = document.createElement("div");
  173. var top = document.createElement("div"); top .className = "top" + ((this.isIE6()) ? " IE6" : "");
  174. var middle = document.createElement("div"); middle.className = "middle" + ((this.isIE6()) ? " MIDDLEIE6" : "");
  175. var bottom = document.createElement("div"); bottom.className = "bottom" + ((this.isIE6()) ? " BOTTOMIE6" : "");
  176.  
  177. middle.innerHTML = text;
  178.  
  179. this.div.appendChild(top );
  180. this.div.appendChild(middle);
  181. this.div.appendChild(bottom);
  182.  
  183. this.div.className = 'tooltip';
  184. this.div.style.position = 'absolute';
  185. this.div.style.visibility = 'hidden';
  186.  
  187. map.getPane(G_MAP_FLOAT_PANE).appendChild(this.div);
  188. };
  189.  
  190. this.remove = function(){
  191. this.div.parentNode.removeChild(this.div);
  192. };
  193.  
  194. this.copy = function(){
  195. return new Tooltip(this.marker, this.text, this.padding);
  196. };
  197.  
  198. this.redraw = function(force){
  199. if (!force)
  200. return;
  201.  
  202. var markerPos = this.map.fromLatLngToDivPixel(this.marker.getPoint());
  203. var iconAnchor = this.marker.getIcon().iconAnchor;
  204. var xPos = (markerPos.x - (this.div.offsetWidth / 2));
  205. var yPos = markerPos.y - iconAnchor.y - this.div.offsetHeight;
  206. this.div.style.top = yPos + 'px';
  207. this.div.style.left = xPos + 'px';
  208. };
  209.  
  210. this.show = function(){
  211. this.div.style.visibility = 'visible';
  212. };
  213.  
  214. this.hide = function(){
  215. this.div.style.visibility = 'hidden';
  216. };
  217.  
  218. this.marker = marker;
  219. this.text = text;
  220. this.prototype = new GOverlay();
  221. };
  222. </script>
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232. <script>$("#miasto").html(geoip_city());</script>
  233. <div id="miasto"></div>
  234.  


tak działa cały skrypt
Go to the top of the page
+Quote Post

Posty w temacie
- maksik   [JavaScript]wynik z js w polu input   3.03.2014, 16:03:36
- - nospor   1) A nie masz przypadkiem div o ID miasto? 2) Nie ...   3.03.2014, 16:05:16
- - maksik   ta funkcja wczesniej wyświetlała miasto z ip w pos...   3.03.2014, 16:17:45
- - nospor   Napisalem dwa proste punkty. Umiesz na nie odpowie...   3.03.2014, 16:19:14
- - maksik   nie ma div, a zmiana html na value nie pomaga   3.03.2014, 16:27:11
- - nospor   Pokaz caly kod po poprawkach, caly HTML, pokaz tez...   3.03.2014, 16:28:28
- - maksik   [PHP] pobierz, plaintext http://j.maxmind.com/app/...   3.03.2014, 16:30:34
- - nospor   Prosilem o kod HTML. W kodzie co pokazales nigdzi...   3.03.2014, 16:34:46
- - maksik   [PHP] pobierz, plaintext <script src="http...   3.03.2014, 16:40:07
- - nospor   masz diva o ID miasto i sie dziwisz ze ci sie zapi...   3.03.2014, 16:44:26
- - maksik   chciałem ci wyłącznie pokazać kod w którym to dzia...   3.03.2014, 16:48:37
- - nospor   Jak juz pisalem w poprzedim poscie ma byc VAL a ni...   3.03.2014, 16:52:28
- - maksik   nic nie zmieniło   3.03.2014, 17:01:34
- - nospor   Nic nie zmienilo czyli co? Nadal w div ci sie pisz...   3.03.2014, 17:04:44
- - maksik   kod html wygląda wyłącznie w ten sposób przy czym ...   3.03.2014, 17:08:12
- - nospor   No ale zmien kolejnosc.... najpierw input, a dopie...   3.03.2014, 17:09:08
- - maksik   Bardzo jestem wdzięczny, problem zażegnano. Mam j...   3.03.2014, 19:22:36
- - nospor   Musisz to pole wyslac do php. Albo normalnie formu...   4.03.2014, 15:43:36


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.12.2025 - 12:27