我正在尝试使用 knockout.js 创建一个按钮来创建文本我不确定是 html 还是 javascript 有问题,但控制台说的是我的“开始”ID 的 onclick 为空。
<div style="margin:0 20px 0 20px;" >
<p data-bind="text: currentQuestion"></p>
<form id="discoutQuestions" action="none">
<button id="start" value="start">start</button>
<label>Answer:</label>
<input type="text" id="answer"/>
<button id="answerSubmit" value="submit" onclick="questionare()">submit</button>
</form>
</div>
document.getElementById('start').onClick(ko.applyBindings(questionList));
document.getElementById('answerSubmit').onClick(function questionare()
{
var correct=0;
var count=0;
var questionList= new questionViewModel();
function next()
{
questionList.setQuestion(questionList.getNext());
ko.applyBindings(questionList);
}
var answer= document.getElementById('answer').value;
if(answer==questionList.answers[0][1]&&count!=questionList.getLength())
{
correct++;
count++;
next();
}
else if(answer!=questionList.answers[0][1]&&count!=questionList.getLength())
{
count++;
next();
}
else
{
react= new message();
if(correct/count>.75)
{
react.setQuestion("Congradualtions! You have won a discount.");
}
else{
react.setQuestion("We are sorry, you did not answer enough questions right ofr a discount.");
}
ko.applyBindings(react);
}
});
此外,我的表单标签不会采取 action="none",而且问题不是 onclick,而是 getElementById。