请帮我调试我的代码:
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title> Miles to Kilometers Conveter</title>
<script type="text/javascript">
/* Defining Table: Program to convert miles to kilometers.
* Input: Miles
* Processing: How many kilometers in a amount of miles inputed
* Output: output total kilometers
*/
function milesToKilo(){
var miles= getElementByID=("milesinput");
var kilo=1.60934;
var k= parseFloat(kilo);
var total= miles*k;
document.getElementById('outputDiv').innerHTML = total;
}
</script>
</head>
<body>
<h2>Miles to Kilometers Converter</h2>
How many Miles?<input type="text" id="milesinput">
<button type="button" onclick="milesToKilo()">Convert</button>
<div id='outputDiv'></div>
</body>
</html>
答案 0 :(得分:1)
这是一个解决方案,您需要获取元素的值并从中解析一个int。
http://plnkr.co/edit/NOYYKx0bYqJ2QJ21prUc?p=preview
function milesToKilo(){
var miles = parseInt(document.getElementById("milesinput").value);
var kilo =1.60934;
var k = parseFloat(kilo);
var total= miles*k;
document.getElementById('outputDiv').innerHTML = total;
}
答案 1 :(得分:0)
In [24]: A
Out[24]:
array([[4, 5, 1],
[8, 0, 1]])
In [25]: B
Out[25]:
array([[4, 1, 1],
[8, 0, 1]])
In [26]: np.where(A == B,A,0)
Out[26]:
array([[4, 0, 1],
[8, 0, 1]])
In [27]: A*(A==B)
Out[27]:
array([[4, 0, 1],
[8, 0, 1]])
应为var miles = getElementById=("milesinput")
:请注意var miles = getElementById("milesinput")
和=
之间缺少getElementById
。除此之外......
(
被分配了miles
的值,这是一个HTML getElementById("milesinput")
- 这是变量JavaScript的特定种,而不是element
。
此类型的number
具有element
属性。您可以使用value
访问它,但它是miles.value
类型。您需要将其转换为如此数字:
string