为什么jquery代码没有在jsfiddle中运行

时间:2012-08-01 06:14:56

标签: javascript jquery

我在jsfiddle上试试...............我不知道为什么它没有运行...........有人帮忙

html section
<html>
    <body>
        <div>The Answer is: </div>
        <div class='answer'></div>
    </body>`enter code here`
</html>


js section
function writeAnswer(answer) { // helper function for output
    $('div.answer').append($('<div>').text(answer));
}

function writedemo() {
    var answer="hello";
    writeAnswer(answer);

    }

}

writedemo();

2 个答案:

答案 0 :(得分:2)

工作演示 http://jsfiddle.net/zJ3yk/

因为您有额外的}

休息应该有助于满足需求:)

<强>码

function writeAnswer(answer) { // helper function for output
    $('div.answer').append($('<div>').text(answer));
}

function writedemo() {
    var answer="hello";
    writeAnswer(answer);

    }
//} <===== this is the culprit and rest demo gives you idea. 

writedemo();​

答案 1 :(得分:0)

检查以下jsfiddle。你可以找到工作的js。

http://jsfiddle.net/shivkant/HQyZe/8/