Skip to content

Instantly share code, notes, and snippets.

@codingwithsara codingwithsara/index.html Secret
Created Aug 13, 2019

Embed
What would you like to do?
jQuery Simple Calculator
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(function(){
$('button').click(function(){
var pushed = $(this).text();
var inputLabel = $('#inputLabel');
if (pushed == '=') {
// 計算
inputLabel.text(eval(inputLabel.text()));
} else if (pushed == 'AC') {
// 全てクリア
inputLabel.text('0');
} else {
if (inputLabel.text() == '0') {
inputLabel.text(pushed);
} else {
inputLabel.text(inputLabel.text() + pushed);
}
}
});
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.