有没有办法将python代码放入javascript onclick函数中?
我正在尝试将一些python代码放入javascript函数中,以便在单击按钮时调用它。我只是想知道在javascript函数中是否有标记或某种内置方式来编写python代码? 我知道我可以通过请求函数打开一个文件或类似的东西来实现这一点,但是如果有一种方法可以将整个解决方案包含在一个文件中,那就太好了 这是我试图输入函数的代码:有没有办法将python代码放入javascript onclick函数中?,javascript,python,html,Javascript,Python,Html,我正在尝试将一些python代码放入javascript函数中,以便在单击按钮时调用它。我只是想知道在javascript函数中是否有标记或某种内置方式来编写python代码? 我知道我可以通过请求函数打开一个文件或类似的东西来实现这一点,但是如果有一种方法可以将整个解决方案包含在一个文件中,那就太好了 这是我试图输入函数的代码: user_input = input("input text here: ") cipher_key = int(input("inpu
user_input = input("input text here: ")
cipher_key = int(input("input cipher key here: "))
for x in user_input:
if x == " ":
print(x)
else:
ord_num = ord(x)
alf_num = ord_num - 97 + cipher_key
en_num = alf_num % 26 + 97
print(chr(en_num))
这取决于你的环境;如果您正在编写一个NodeJS程序,您可以按照这里的说明来完成。如果您正在编写客户端代码(用于web浏览器),则不能 编辑 您的代码相对简单,因此可以将函数转换为js。假设您正在编写Nodejs代码:
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("input text here: ", function(user_input) {
rl.question("input cipher key here: ", function(cipher_key) {
rl.close();
cipher_key = parseInt(cipher_key)
for (let i = 0; i < user_input.length(); i++) {
const x = user_input[i];
if (x === " ")
process.stdout.write(x)
else {
const ord_num = x.charCodeAt(0)
const alf_num = ord_num - 97 + cipher_key
const en_num = alf_num % 26 + 97
process.stdout.write(String.fromCharCode(en_num))
}
}
});
});
const readline=require(“readline”);
const rl=readline.createInterface({
输入:process.stdin,
输出:process.stdout
});
rl.问题(“此处输入文本:”,函数(用户输入){
问题(“此处输入密码密钥:”,函数(密码密钥){
rl.close();
cipher\u key=parseInt(cipher\u key)
for(设i=0;i
onclick
只能运行客户端代码,Python在服务器上运行。可能有一个类似Python的javascript库。基本上是移植的功能。你想在点击上做什么?最有可能的是,如果你能用Python来做这件事,你也可以用Javascript来做。@SeyiDaniel烧瓶端点在服务器上运行。不,我只是说你不能直接在onclick中运行Python(或PHP,或任何其他服务器端语言)。您可以使用AJAX向服务器发送请求,并且可以用任何语言实现服务器处理。