gpt4 book ai didi

javascript - jquery警告框简单计算

转载 作者:行者123 更新时间:2023-11-30 12:26:49 25 4
gpt4 key购买 nike

我想用js和jQuery做简单的计算。关于字段中的值,alertbox 应该显示计算。这是我的代码:

<!DOCTYPE html> 
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head >
<body>

<p id="demo"></p>

<script>
$(document).ready(function(){
$("#btn1").click(function(){
alert("Solution: " + $("#demo").val());
});
});

function myFunction(a, b) {
var a;
var b;
return a * b;
}

document.getElementById("demo").innerHTML = myFunction(a, b);
</script>

<input id="a" type="text" value="10" />
<input id="b" type="text" value="5" />
<button id="btn1">Result</button>
</body>
</html>

最佳答案

给你:

<script>
$(document).ready(function(){

//Grab Values
$('#demo').val(myFunction($('#a').val(), $('#b').val()));

$("#btn1").click(function(){
alert("Solution: " + $("#demo").val());
});
});
function myFunction(a, b) {
return a * b;
}
</script>

<input id = "a" type = "text" value = "10" />
<input id = "b" type = "text" value = "5" /> <button id = "btn1"> Result </button>

关于javascript - jquery警告框简单计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29078385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com