Javascript using variables to create a url through buttons

前端 未结 1 950
星月不相逢
星月不相逢 2021-01-25 08:01

I have a button on my website that when clicked generates a word. This word is then used in a url call to download a specific file.

 
相关标签:
1条回答
  • 2021-01-25 08:04

    Try this it's working fine :

    Html :

    <button class="button1" onclick="myFunction();">cafe</button>
    

    Script :

     var cafe = [];
     window.myFunction = function() {
     cafe.push('cafenew');
     console.log(cafe);
     var name = cafe[0];
     var src = "https://www.dropbox.com/s/"+name+".kml?dl=1";
     console.log(src);
     }
    

    Working fiddle : https://jsfiddle.net/8etxu8pr/

    0 讨论(0)
提交回复
热议问题