我是jQuery新手 如果我有这样的列表:
add one
add two
add three
如何在容器#calculate
中计算这些值。
何时
添加一个
单击
时,应将1加到容器中添加两个
单击它应该在容器中显示3,因此应该可以无休止地单击它们,并且每次将其乘以您要添加的数字
答案 0 :(得分:1)
使用全局变量,该变量初始化为0。
使用[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
Function Pick-Date {
$Cal = New-Object System.Windows.Forms.MonthCalendar
$Cal.ShowWeekNumbers = $true
$Cal.MaxSelectionCount = 1
$Cal.Dock = 'Fill'
$Form = New-Object Windows.Forms.Form
$Form.text = "Colocar fecha que desea enviar. Y presiona Enter"
$Form.Size = New-Object Drawing.Size @(656,620)
$btnSelect = New-Object System.Windows.Forms.Button
$btnSelect.Size = "100,100"
$btnSelect.add_Click({ $Form.close() })
$btnSelect.Location = New-Object System.Drawing.Point(530,480)
$btnSelect.Text="ENTER"
$Form.Controls.Add($btnSelect )
$Form.AcceptButton = $btnSelect
$Form.Controls.Add($Cal)
$Form.Add_Shown({$Form.Activate()})
[void]$Form.ShowDialog()
return (Get-Date($Cal.SelectionStart))
}
$fecha = Pick-Date
$archivos=Get-ChildItem "$root\UNB\FINAL_TEXTO\" -Filter *.txt | Where-Object {$_.CreationTime.Date -EQ $fecha}
调用所需的函数,在这种情况下,Error loading preview
并将计数器值设置为结果div。
async function uploadImageAsync(itemImage, passedParameter, ItemName, ItemDesc, ItemPrice, ItemWeight) {
const response = await fetch(itemImage);
const blob = await response.blob();
console.log("uri of the elements ius", blob)
var storageRef = firebase.storage().ref();
var file = blob
var metadata = {
contentType: 'image/jpeg',
};
const timeStamp = Date.now();
var uploadTask = storageRef.child('CategoryDescription' + "/" + `${passedParameter}` + "/" + `${ItemName}`).put(file, metadata);
_pickImage = async () => {
const { CAMERA, CAMERA_ROLL } = Permissions;
const permissions = {
[CAMERA]: await Permissions.askAsync(CAMERA),
[CAMERA_ROLL]: await Permissions.askAsync(CAMERA_ROLL),
};
if (permissions[CAMERA].status === 'granted' && permissions[CAMERA_ROLL].status === 'granted') {
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: false,
aspect:[4,3],
quality: 0.5,
});
// console.log(result);
if (!result.cancelled) {
this.setState({ itemImage: result.uri });
}
}
答案 1 :(得分:1)
var TotalAmount = 0;
function btnClick(Param) {
TotalAmount += Number(Param);
console.log(TotalAmount);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="btnOne" onclick="btnClick(1)">Add one</button>
<button id="btnTwo" onclick="btnClick(2)">Add two</button>
<button id="btnThree" onclick="btnClick(3)">Add three</button>
答案 2 :(得分:1)
尝试一下
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="result">0</div>
<button value="1" onClick="sum(this.value)">Add One</button>
<button value="2" onClick="sum(this.value)">Add Two</button>
<button value="3" onClick="sum(this.value)">Add Three</button>
<script>
var total = 0;
function sum(num){
total += parseInt(num);
$("#result").html(total);
}
</script>
答案 3 :(得分:1)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
Result: <span id="result"></span><br />
Number of clicks: <span id="clickNumber"></span><br />
</div>
<div>
<button onclick="addFunction(1)">
Add One
</button>
<button onclick="addFunction(2)">
Add Two
</button>
</div>
<script>
let result = 0;
let clickNumber = 0
function addFunction(n){
result += n;
clickNumber++;
$("#result").text(result);
$("#clickNumber").text(clickNumber);
}
</script>
答案 4 :(得分:0)
var total = 0;
function add(num){
if(total==0){
total += num;
$("#res").html(total);
}else{
total *= num;
$("#res").html(total);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="res">0</div>
<button onClick="add(1)">Add One</button>
<button onClick="add(2)">Add Two</button>
<button onClick="add(3)">Add Three</button>
答案 5 :(得分:-1)
您可以绑定单击事件以获取按钮文本,如下所示
$("button").click(function(){
nummber = nummber +( +this.text());
});
您无需在html中附加点击列表器,就可以在按钮中添加类以仅在javascript中找到计算器按钮