开发者

Javascript alert function in jss file

开发者 https://www.devze.com 2023-04-12 10:49 出处:网络
I have a problem where I want to show a bunch of variables in an alert box when I click on a button on the webpage.

I have a problem where I want to show a bunch of variables in an alert box when I click on a button on the webpage.

I don't want to create a bunch of variables in a XHTML file and then output those since I already calculated everything in my javascript file. I referenced the Javascript file to my XHTML file and the variables show up if i just do a plain document.write

The variables are just numbers I calculated on a range of values. I want to display them in an alert box when I click on a button on the webpage itself. Now I can display them in an alert box when I go to the webpage, but I can't figure out how to display them when I click on a button.

For example,:

My .jss file contains the following:

var num5 = 5;
var num6 = 6;
var num7 = 7;
var num8 = 8;
var num9 = 9;
var num10= 10;

My xhtml file:

<?xml version = "1.0" encoding = "utf-8" ?>
<开发者_C百科;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtmll/DTD/xhtmll-strict.dtd">

 <html xmlns = "http://www.w3.org/1999/xhtml">
    <head>
        <title>ShowNums.html</title>
    </head>
    <body>
        <script type = "text/javascript" src = "test.js">
        </script>
        <input type="button" onclick="show_alert()" value="Click" />    
    </body>
</html>

I referenced my .jss file to my XHTML file and want to display those numbers. I can easily encode them into an alert but I would rather have a popup alert box that would display them when the user clicks on a button(i.e. the Click button). How would I do this? I tried looking for help but I can't seem to find it :\


Are you just looking for this show_alert() function?

function show_alert() {
    var msg = num5 + ", " + num6 + ", " + num7 + ", " + num8 + ", " + num9 + ", " + num10;
    alert(msg);    // shows "5, 6, 7, 8, 9, 10"
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号