[英]Javascript onClick function not working properly
<!DOCTYPE html>
<html>
<head>
<title> Delete Paper </title>
</head>
<body>
<script>
document.write('<?php
session_start();
$username = "";
$password = "";
$server = "localhost";
$user = "";
$pass = "";
$db = "test";
$userid = $_SESSION['userid'];
$conn = new mysqli($server,$user,$pass, $db);
$sql = "SELECT * FROM questionpapercount where userid='$userid'";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()){
$paper = $row['paperid'];
echo "<input type=checkbox name=$paper /> $paper ";
}
$conn->close();
?> ');
function deletequery(){
alert('abcd');
}
</script>
<input type=button value=Delete onclick=deletequery() />
</body>
</html>
My javascript function is not working properly.我的 javascript 功能无法正常工作。 If i write onclick a simple alert('abcd');
如果我写 onclick 一个简单的 alert('abcd'); then it is working fine, but if i write a function instead then it is not working.
那么它工作正常,但如果我写一个函数,那么它就不起作用了。
delete
is a operator in JavaScript, so these lines won't work: delete
是JavaScript 中的运算符,因此这些行不起作用:
function delete(){
alert('abcd');
}
document.write("<input type=button value=Delete onclick=delete(); />");
Rename your function to fix your code.重命名您的函数以修复您的代码。 You should also put your HTML attributes in quotes:
您还应该将 HTML 属性放在引号中:
function deleteHandler(){
alert('abcd');
}
document.write('<input type="button" value="Delete" onclick="deleteHandler();" />');
Delete 是一个关键字,因此您可以使用“del”或其他名称来代替 delete。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.