最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

variables - Pass Javascript Alert a Value - Stack Overflow

programmeradmin0浏览0评论

I'm looking for a simple javascscript alert box. I need to be able to pass the alert box a string of text.

Is something like this possible? My syntax is probably wrong.

<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert(my_string_here);
}
</script>
</head>
<body>

<input type="button" onclick="show_alert()" value="Show alert box" string="alert for system number 2" />

</body>
</html>

I'm looking for a simple javascscript alert box. I need to be able to pass the alert box a string of text.

Is something like this possible? My syntax is probably wrong.

<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert(my_string_here);
}
</script>
</head>
<body>

<input type="button" onclick="show_alert()" value="Show alert box" string="alert for system number 2" />

</body>
</html>
Share Improve this question asked Nov 4, 2009 at 20:59 shaissshaiss 2,0105 gold badges23 silver badges34 bronze badges 1
  • I know my example makes no sense, I'm not a JS guru. thank you Bjorn for the tip, that worked perfect! – shaiss Commented Nov 4, 2009 at 21:10
Add a ment  | 

6 Answers 6

Reset to default 4
<html>
<head>
<script type="text/javascript">
function show_alert(my_string)
{
alert(my_string);
}
</script>
</head>
<body>

<input type="button" onclick="show_alert('This will alert!')" value="Show alert box" string="alert for system number 2" />

</body>
</html>

This makes no sense thou. Better solution:

<html>
<head>
</head>
<body>

<input type="button" onclick="alert('Doh!')" value="Show alert box" string="alert for system number 2" />

</body>
</html>

Try:

<input type="button" onclick="alert('alert for system number 2');" value="Show alert box" />

What are you trying to do? alert('Your string here') should do the trick if you really need an alert.

Yes you can

function testAlert(val){alert(val);}

Yes this is possible

<script type="text/javascript">
function testAlert(val){alert(val);}
</script>

<input type=text onclick='testAlert(this.string)' string="something" value="clik here">

alert("alert for system number 2");

发布评论

评论列表(0)

  1. 暂无评论