1
所以,我有一个带有两个滑块的网页,用于设置数值和四个单选按钮,用于选择计算操作和“计算”按钮。如何检测滑条值和选择哪个操作,然后相应地计算这些值并将它们输出到“计算”按钮的标签上?注意:我对javascript/jquery完全新鲜。使用JQuery进行计算/ javascript
代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$("#slider-range-max").slider({
range: "max",
min: 1,
max: 1000,
value: 0,
slide: function (event, ui) {
$("#amount").val(ui.value);
}
});
$("#amount").val($("#slider-range-max").slider("value"));
});
</script>
</head>
<body>
<p>
<label for="amount">First value:</label>
<input type="text" id="amount" style="border: 0; color: #f6931f; font-weight: bold;" />
</p>
<div id="slider-range-max"></div>
</body>
</html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$("#slider-range-max2").slider({
range: "max",
min: 1,
max: 1000,
value: 0,
slide: function (event, ui) {
$("#amount2").val(ui.value);
}
});
$("#amount2").val($("#slider-range-max2").slider("value"));
});
</script>
</head>
<body>
<p>
<label for="amount">Second value:</label>
<input type="text" id="amount2" style="border: 0; color: #f6931f; font-weight: bold;" />
</p>
<div id="slider-range-max2"></div>
</body>
</html>
<br />
<br />
<br />
<div id=operacija">
Choose operation:<br />
<br />
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$("#radio").buttonset();
});
</script>
</head>
<body>
<form>
<div id="radio">
<input type="radio" id="radio1" name="radio" /><label for="radio1">Addition</label>
<input type="radio" id="radio2" name="radio" /><label for="radio2">Substraction</label>
<input type="radio" id="radio3" name="radio" /><label for="radio3">Multiplication</label>
<input type="radio" id="radio4" name="radio" /><label for="radio4">Division</label>
</div>
</form>
</body>
</html>
</div>
<br />
<br />
<div id="gumb1">
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$("button").button().click(function (event) {
event.preventDefault();
});
});
</script>
</head>
<body>
<button>Calculate</button>
</body>
</html>
</div>
<br />
<br />
<div id=rezultat">
<label for="amount">Result:</label>
<input type="text" id="Text1" style="border: 0; color: #f6931f; font-weight: bold;" />
</div>
在你的滑块中你正在做'min:1,max:1000,value:0,';即您将初始_value_设置为低于_minimum_。此外,这看起来不像有效的HTML - 多个“”元素,“
”元素和“<!doctype ..”。您还多次包含脚本。这是多页还是只有一页? – 2013-03-17 22:07:01它只有1页。 – cvenko 2013-03-17 22:15:46
这就是这个页面的样子:http://shrani.si/f/3L/3i/36jR3xsi/sample.png – cvenko 2013-03-17 22:19:52