这是我的代码:
with open('index.html', 'w') as html:
title = input('Title of the page? ').capitalize()
h2 = input('Heading for your website: ').capitalize()
p1 = input('First paragraph: ').capitalize()
p2 = input('Second paragraph: ').capitalize()
a = '''
<html>
<head>
<link href="css/bootstrap.css" rel="stylesheet">
<title> {} </title>
</head>
<body>
<center>
<h2> {} </h2>
</center>
<div id='well'>
<p style='position: relative; left: 100px'> {} </p>
<p style='position: relative; left: 100px'> {} </p>
<input type='button' value='test' onClick='Button()'>
<p id='lol'> </p>
</div>
<script>
function Button()
\{
document.getElementById('lol').innerHTML = 'hello';
\}
</script>
</body>
</html>
'''.format(title, h2, p1, p2)
html.write(a)
在我尝试使用括号添加 javascript 函数之前,一切都运行良好{ }
,并且程序认为它们是格式函数的一部分,我该如何解决这个问题?我试过把 \ 放在它前面,但它没有用,(顺便说一句,我应该在这个非常简单的概念中添加任何想法吗?:))