我有大量的选择下拉菜单,我正在尝试使用每个()获取每个选定的值。我似乎无法做对。我该怎么做呢?
这是我的代码:
$('#aTable select option:selected').each(function(){
console.log($(this).text());
});
答案 0 :(得分:1)
enter code here
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Buttons extends Applet implements ActionListener {
int num1 = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
double sum = 5;
Label total, vend, welc;
TextArea result;
public void init()
{
setLayout(new GridLayout(5, 0));
welc = new Label (" Welcome to the Buttons!");
add(welc);
vend = new Label ("Please press a button now.");
add(vend);
b1 = new Button("Bread");
add(b1);
b1.addActionListener(this);
b2 = new Button("Butter");
add(b2);
b2.addActionListener(this);
b3 = new Button("Soup");
add(b3);
b3.addActionListener(this);
b4 = new Button("Water");
add(b4);
b4.addActionListener(this);
b5 = new Button("Finish and pay");
add(b5);
b5.addActionListener(this);
cancel = new Button("Cancel");
add(cancel);
cancel.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
Object obj=e.getSource();
if (obj == cancel)
{
result.requestFocusInWindow();
result.selectAll();
result.setText("");
num1 = 0; num2 = 0; num3 = 0; num4 = 0;
}
}
});
total = new Label (" You order total");
add(total);
result = new TextArea ( 10, 30);
add(result);
result.setEditable(false);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b1){
num1++;
showStatus("You have chosen " + num1 + " bread");}
if (e.getSource() == b2){
num2++;
showStatus("You have chosen " + num2 + " butter");}
if (e.getSource() == b3){
num3++;
showStatus("You have chosen " + num3 + " soup");}
if (e.getSource() == b4){
num4++;
showStatus("You have chosen " + num4 + " water");}
if (e.getSource() == b5){
result.requestFocusInWindow();
sum = addition(num1, num2, num3, num4);
result.setText(" Bread: "+ num1 +" selected\n"
+" Butter: "+ num2 +" selected\n"
+" Soup: "+ num3 +" selected\n"
+" Water: "+ num4 +" selected\n"
+ "Total money due is: € " +Double.toString(sum));
}
}
public double addition(int x, int y, int z, int t)
{
return 1.2*x + 3.1*y + 2*z + 1.5*t;
}
Button b1, b2, b3, b4, b5, cancel;
}
答案 1 :(得分:0)
使用#include <iostream>
#include <type_traits>
#include <unordered_map>
#include <string>
std::string Serialize(std::string s) {
return '"' + s + '"';
}
template <
typename T,
typename = typename std::enable_if<std::is_arithmetic<T>::value>::type
>
std::string Serialize(T n) {
return std::to_string(n);
}
template <typename Key, typename Val, typename ...Other>
std::string Serialize(typename std::unordered_map<Key, Val, Other...> const &um) {
std::string result = "{";
bool comma = false;
for(const auto& kv : um) {
if(comma) { result += ','; }
else { comma = true; }
result += Serialize(kv.first);
result += ':';
result += Serialize(kv.second);
}
result += '}';
return result;
}
int main() {
std::unordered_map<std::string, int> mymap;
mymap["one"] = 1;
mymap["two"] = 2;
auto serialized = Serialize(mymap);
std::cout << serialized << '\n';
}
获取所选文本。它的工作原理
<强>演示: - 强>
{"two":2,"one":1}
&#13;
this.options[this.selectedIndex].text
&#13;