在我的 JavaScript 代码中,我有以下行:
document.write("</form><button style='margin-top:100px; width:150px; position:absolute; left:50%; margin-left:-75px' type='button' onclick='Proceed('test')'>Se resultat</button>");
样式和类型属性工作正常,但是当我尝试将参数传递给 JavaScript 函数 Proceed 时,它不起作用。我也试过(\'test\')
我该如何解决这个问题?
编辑:完整的 html 脚本
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Title here.</title>
<script>
function Proceed(var test)
{
alert(test);
}
</script>
</head>
<body style="font-family:Palatino">
<img src="logo.png"/>
<hr/>
<h1 style="text-align:center">Description here.</h1>
<script>
if (window.XMLHttpRequest)
{
request=new XMLHttpRequest();
}
else
{
request=new ActiveXObject("Microsoft.XMLHTTP");
}
request.open("GET","data.xml",false);
var XMLdocument;
request.onreadystatechange=function()
{
if (request.readyState==4)
{
XMLdocument = request.responseXML;
}
};
request.send();
var questions = XMLdocument.getElementsByTagName("question");
for(i = 0; i < questions.length; i++)
{
var x = questions[i];
var questionvalue = x.getElementsByTagName("questionvalue");
document.write("<p style='margin-top:50px; font-size:20px; font-weight:bold; text-align:center'>" + questionvalue[0].childNodes[0].nodeValue + "</p>");
var answers = XMLdocument.getElementsByTagName("answer");
document.write("<form>");
for(n = 0; n < answers.length; n++)
{
y = answers[n];
var answervalue = y.getElementsByTagName("answervalue");
document.write("<input style='margin-left:43%; margin-right:20px;' type='radio' name='" + questionvalue[0].childNodes[0].nodeValue + "' value='" + answervalue[0].childNodes[0].nodeValue + "'>" + answervalue[0].childNodes[0].nodeValue + "<br/>");
}
document.write("</form><button style='margin-top:100px; width:150px; position:absolute; left:50%; margin-left:-75px' type='button' onclick='Proceed(\"test\")'>Se resultat</button>");
}
</script>
</body>
</html>