我的页面上有一些可选的div
public class Meerkan_Bank extends Account {
//Creating bank accounts and giving info.
Account[] bank;
int numberOfAccounts;
public Meerkan_Bank() {
bank = new Account[20];
numberOfAccounts = 0;
}
//Getter
public int getNumberOfAccounts() {
return numberOfAccounts;
}
//adds account to array bank
public void addAccount(Account a) {
bank[numberOfAccounts] = a;
numberOfAccounts++;
}
//adds account using balance
public void addAccount(double initBalance) {
bank[numberOfAccounts] = new Account(initBalance);
numberOfAccounts++;
}
//get total balance
public double getTotalBalance() {
double sum = 0.0;
for(int i=0; i < this.getNumberOfAccounts(); i++) {
sum += bank[i].getBalance();
}
return sum;
}
//returns Account with highest balance in the array
public String getMaxBalance() {
Account largest = bank[0];
for(int i = 1; i<bank.length; i++) {
Account current = bank[i];
**if(current.getBalance() > largest.getBalance())**
largest = current;
}
return largest.toString();
}
//toString
public String toString() {
Account maxBalance = new Account(bank[0].getBalance());
System.out.println("The accounts in this bank are: ");
for(int i = 0; i<this.getNumberOfAccounts(); i++) {
if(bank[i] != null)
System.out.println(bank[i]);
}
return "\nThe total balance in the bank is: " +this.getTotalBalance()+
"\nThe account with the highest balance in the bank is: ";
}
}
`````````````````````````
`````````````````````````
//TestBank
import java.util.Scanner;
public class Meerkan_TestBank {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Account date = new Account();
Meerkan_Bank bank = new Meerkan_Bank();
for(int i=0; i<5; i++) {
System.out.println("Enter a balance");
double balance = input.nextDouble();
bank.addAccount(balance);
}
//print total and max balances
System.out.println(bank.toString());
System.out.println(bank.getMaxBalance());
}
我正在寻找正确的jQuery,它将捕获“ selectable-divs”集合中已选择/单击的内容的ID值。 jQuery的可选部分工作正常,但是,当我单击div时,它在警报框中返回值“ undefined”
答案 0 :(得分:0)
您可以使用纯jQuery和Javascript
$(function() {
$('#selectable-divs div').click(function(){
var x = this.id;
alert(x);
});
});
ES6的最后一个JavaScript版本
$(function() {
$('#selectable-divs div').on('click', function(){
let x = this.id
alert(x)
});
});