[英]The new quote function in my script.js file does not make the author name appear
[英]Cant make my script.js while it works on Codeacademy
所以我在html文件中使用javascript腳本編寫了一個計數器(使用Angular 2)。 這是我的兩個文件(不包括樣式之一)。
pokehunted.component.html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type="text/javascript" src="../script.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="displayCounter">
<button class="box" onclick="modify_qty(1)">
<p>Pikachu</p>
<input type="image" src="../../assets/img/pikachu.png" />
</button>
<div class="counter">
<label for="qty"><abbr title="Quantity">Rencontres</abbr></label>
<input id="qty" value="0" />
</div>
</div>
</body>
</html>
的script.js
function modify_qty(val) {
var qty = document.getElementById('qty').value;
var new_qty = parseInt(qty,10) + val;
if (new_qty < 0) {
new_qty = 0;
}
document.getElementById('qty').value = new_qty;
return new_qty;
}
問題是,我在Codeacademy上對此進行了編碼,並且效果很好。 目的是創建一個div按鈕,以遞增其下方的計數器。 在Codeacademy上確實如此,在我的項目中,計數器沒有移動。
您知道我在做什么錯嗎? 非常感謝。
好吧,我修好了! 我必須將腳本放入我的angular-cli.json中,而不是將其放入HTML中。 我真的不知道為什么我不能只使用標簽來做到這一點,但是這樣做是可行的。 這是我在json中修改的部分:
"apps": [
{
"scripts": [
"app/pokehunted/script.js"
],
[...]
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.