Ich habe gerade angefangen zu lernen JavascriptWie funktioniert Code Abkürzung in diesem Programm
Hier ist mein Code unten.
Ich denke, es ist zu lang, also brauche ich eine Hilfe, um es kürzer zu machen.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<button onclick="myFunction()">do it</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
var x = document.createElement("INPUT");
x.setAttribute("type", "text");
x.setAttribute("value", "");
x.setAttribute("id", "top2");
document.body.appendChild(x);
var x = document.createElement("INPUT");
x.setAttribute("type", "text");
x.setAttribute("value", "");
x.setAttribute("id", "top");
document.body.appendChild(x);
var x = document.createElement("SELECT");
x.setAttribute("id", "mySelect");
document.body.appendChild(x);
$("#mySelect").append($("<option value='toplama'></option>").text("Toplama"));
$("#mySelect").append($("<option value='çıkarma'></option>").text("Çıkarma"));
function myFunction() {
var sayi1 = document.getElementById('top').value;
var sayi2 = document.getElementById('top2').value;
var sonuc;
if ($("#mySelect").val() == "toplama") {
sonuc = parseInt(sayi1) + parseInt(sayi2);
alert(sonuc);
} else if ($("#mySelect").val() == "çıkarma") {
sonuc = parseInt(sayi1) - parseInt(sayi2);
alert(sonuc);
}
}
</script>
</body>
</html>
Wie kann ich diesen JavaScript-Code verbessern?
Was soll ich tun?
kann dieser Link hilft Ihnen http://javascript.crockford.com/code.html –