我试图让一个按钮来创建一个使用文本knockout.js我不知道它这是使用问题的HTML或JavaScript,但什么控制台说是否是我的“开始”的onclick id为null 。为什么我的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);
}
});
此外,我的表单标签不会采取行动=“none”和它不是,这是一个问题的onclick,它的的getElementById。
的onclick事件所产生的神奇事件对象不是错误,它的的getElementById即返回null –