在Javascript

时间:2016-02-23 22:59:57

标签: javascript python html alert

我无法将python变量打印到Javascript警告框中。有任何想法吗? 到目前为止,这是我的代码,我尝试了不同的变体,似乎没有任何效果。

#!/bin/python
variable="hi"
print "Content-type: text/html"
print
print '''<html>
<head><title>Python Script</title></head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<body>
'''
print "<script>"
print "alert('Hello! I am an alert box!!  %s ');"
print "</script>"% (variable)
'''
</body>
</html>'''

2 个答案:

答案 0 :(得分:3)

print '''<script>
alert('Hello! I am an alert box!!  %s ');
</script>''' % (variable)

答案 1 :(得分:0)

print "alert('Hello! I am an alert box!!  %s ');"% (variable)
print "</script>"

你必须在占位符相同的字符串上进行替换...