简体   繁体   English

单击按钮时将图片附加到div

[英]appending a picture to div when button is clicked

What I'm trying to do is have users input to be added to the string and the picture of google streetview append to the div called map 我想做的是让用户输入要添加到字符串中,并将Google Streetview的图片附加到称为map的div上

I tried two different codes but neither worked. 我尝试了两种不同的代码,但均无济于事。

$("#search").click(function(){
var citySearch = $("#city").val();
var map = $("map");
var streetView = "https://maps.googleapis.com/maps/api/streetview?size=400x400&location="+ citySearch + "";
map.append('<img src="'+ streetView +'">')

})

and also used this with the button being onclick myFunction and onsumbit myFunction 并将其与onclick myFunction和onsumbit myFunction按钮一起使用

function myFunction(){
var citySearch = $("#city").val();
var map = $("map");
var streetView = "https://maps.googleapis.com/maps/api/streetview?size=400x400&location="+ citySearch + "";
map.append('<img src="'+ streetView +'">')

}

HTML 的HTML

<input type="text" name="" id="city">
<button id="search" onclick="myFunction()">Submit</button>

<div id="map">

</div>

如果您打算在ID为“ map”的div内渲染图像,则您的jQuery选择器必须为#map ,而不是map

var map = $("#map");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM