我試圖讓一個按鈕來創建一個使用文本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 –