<!DOCTYPE html>
<html>
<head>
<title>Play Rock Paper Scissors (MK Edition)</title>
</head>
<body>
<button onclick="Play Rock Paper Scissors(MK Edition)">Play Rock Paper Scissors (MK Edition)</button>
<script>
function Play Rock Paper Scissors(MK Edition) {
// Get the path to the Python script.
var pythonScriptPath = "path/to/python/script.py";
// Run the Python script.
subprocess.run(["python", pythonScriptPath]);
}
当我尝试单击播放按钮时启动剪刀石头布游戏时,我的代码中收到两个语法错误。
我仍在尝试修改它并查找任何语法错误等,但我不确定是否是这样。我看到的错误消息说“未捕获的语法错误:缺少(在形式参数之前”和“未捕获的语法错误:意外的标记:标识符”。我的期望是当用户单击“玩石头剪刀布”按钮时,石头剪刀布游戏提示将会弹出这样你就可以玩了。
乍一看,您的 Javascript 函数名称似乎存在语法错误。函数名称中不能有空格,并且应为参数声明保留括号。您可以像这样应用这些更改:
<!DOCTYPE html>
<html>
<head>
<title>Play Rock Paper Scissors (MK Edition)</title>
</head>
<body>
<button onclick="playRockPaperScissors()">Play Rock Paper Scissors (MK Edition)</button>
<script>
function playRockPaperScissors() {
// Get the path to the Python script.
var pythonScriptPath = "path/to/python/script.py";
// Run the Python script.
subprocess.run(["python", pythonScriptPath]);
}
</script>
</body>
</html>
按钮的 onClick 属性现在调用 playRockPaperScissors() 函数。