javascript - Bootstrap with JS, result of a function in popover -


this code temperature of london weather api. works correctly (images local hence won't show):

<!doctype html> <html>     <head>         <meta charset="utf-8" />         <meta name="format-detection" content="telephone=no" />         <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />         <link rel="stylesheet" type="text/css" href="css/body.css" />          <meta name="msapplication-tap-highlight" content="no" />     </head>     <body>         <script src="http://code.jquery.com/jquery-2.0.0.js"></script>         <script language="javascript" type="text/javascript">         <!--             function foo(callback) {                 $.ajax({                 url: "http://api.openweathermap.org/data/2.5/weather?q=london",                 datatype: 'json',                 success: callback                 });             }              function mycallback(result) {                 var temp = json.stringify(json.parse(result.main.temp));                 var kelvin = 272;                 var centigrade = math.round(temp-kelvin);                  if (centigrade <= 25) {                     //alert("temperature : "+math.round(centigrade)+" c");                     var temp = document.getelementbyid("temp");                     temp.style.fontsize = "20px";                     temp.innerhtml = centigrade+"° c , cool&nbsp;&nbsp;&nbsp;"+"<img src= \"img/tlogo2.svg\"/>";                     //document.getelementbyid("temp").innerhtml = centigrade+"° c , cool&nbsp;&nbsp;&nbsp;"+"<img src= \"img/tlogo2.svg\"/>";                 }                 else if (centigrade > 25) {                     var temp = document.getelementbyid("temp");                     temp.style.fontsize = "20px";                     temp.innerhtml = centigrade+"° c , cool&nbsp;&nbsp;&nbsp;"+"<img src= \"img/tlogo3.svg\"/>";                     //document.getelementbyid("temp").innerhtml = centigrade+"° c , it's hot !!! "+"<img src= \"img/tlogo3.svg\"/>";                 }             }         </script>          <div style="position: absolute; left: 30px; top: 75px;">              <img src="img/temlogo.svg" width="35" height="35" onclick="foo(mycallback);"/>         </div>          <p id="temp"></p>     </body> </html> 

from tutorials point , bootstrap website have tried use dissmissable popover. works fine too:

<!doctype html> <html>      <body>         <meta charset="utf-8">         <meta http-equiv="x-ua-compatible" content="ie=edge">         <meta name="viewport" content="width=device-width, initial-scale=1">         <script src="http://code.jquery.com/jquery-2.0.0.js"></script>         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>         <script language="javascript" type="text/javascript">             $(function() {                 $("[data-toggle='popover']").popover();             });         </script>     </body>     <a href="#" tabindex="0" class="btn btn-lg btn-danger" role="button" data-toggle="popover" data-trigger="focus" title="temperature" data-content="40c">temperature</a> </html> 

now trying want temperature popover element. ie. if click on image button, should trigger temperature acquiring function , show temperature , image related in popover box. here 2 challenge facing.

  1. setting image instead of red button , temperature data
  2. list item , image ie. tlogo2.svg appeared in pop on box.

so can suggest how set that?

edit : have tried attain said. nothing happened. code goes here:

<!doctype html> <html>  <body>     <meta charset="utf-8">     <meta http-equiv="x-ua-compatible" content="ie=edge">     <meta name="viewport" content="width=device-width, initial-scale=1">     <script src="http://code.jquery.com/jquery-2.0.0.js"></script>     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>     <script language="javascript" type="text/javascript">  //function function foo(callback) {     $.ajax({     url: "http://api.openweathermap.org/data/2.5/weather?q=london",     datatype: 'json',     success: callback     }); }  function mycallback(result) { var temp = json.stringify(json.parse(result.main.temp)); var kelvin = 272; var centigrade = temp-kelvin; alert("temperature : "+math.round(centigrade)+" c"); //document.getelementbyid("temp").innerhtml = "temperature : "+math.round(centigrade)+" c"; }          $(function() {             $("[data-toggle='popover']").popover(mycallback(result));         });     </script> </body> <a href="#" tabindex="0" class="btn btn-lg btn-danger" role="button" data-toggle="popover" data-trigger="focus" title="temperature" data-content="40c">temperature</a>  </html> 

i adding addition. people don't confuse , see want. want result of function ie temperature 23 c pop on element code:

<!doctype html> <html>  <body>     <meta charset="utf-8">     <meta http-equiv="x-ua-compatible" content="ie=edge">     <meta name="viewport" content="width=device-width, initial-scale=1">     <script src="http://code.jquery.com/jquery-2.0.0.js"></script>     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>     <script language="javascript" type="text/javascript">  //function  function foo(callback) {     $.ajax({     url: "http://api.openweathermap.org/data/2.5/weather?q=london",     datatype: 'json',     success: callback     }); }  function mycallback(result) { var temp = json.stringify(json.parse(result.main.temp)); var kelvin = 272; var centigrade = temp-kelvin; alert("temperature : "+math.round(centigrade)+" c"); //document.getelementbyid("temp").innerhtml = "temperature : "+math.round(centigrade)+" c"; }   $(function() {                 $("[data-toggle='popover']").popover(mycallback);             });     </script> </body> <a href="#" tabindex="0" class="btn btn-lg btn-danger" role="button" data-toggle="popover" data-trigger="focus" title="temperature" data-content= "mycallback(result);" >temperature</a>  </html> 

so let me know need change.

maybe can popover on hover, here example

  $(function() {       $('[title]').attr("data-rel", "tooltip");       $("[data-rel='tooltip']")           .attr("data-placement", "top")           .attr("data-content", function() {               return $(this).attr("title")           })           .removeattr('title');         var showpopover = function() {           $(this).popover('show');       };       var hidepopover = function() {           $(this).popover('hide');       };       $("[data-rel='tooltip']").popover({           trigger: 'manual'       }).click(showpopover).hover(showpopover, hidepopover);    }); 

use this

 <a href="#" tabindex="0" class="btn btn-lg btn-danger" title="40c">temperature</a> 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -