如果选择了第一个项目,我会返回1(如果它从0开始计数,则返回0)。如果选择了第二个项目,我会回来2.依此类推。
答案 0 :(得分:0)
$ which g++
/usr/bin/g++
$ g++ --version
g++ (20140812 (SCEL u2.0.0.0)) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ main.cc
main.cc: In function ‘int main()’:
main.cc:4:2: error: ‘unique_ptr’ is not a member of ‘std’
std::unique_ptr<int> p_int(new int(3));
^
main.cc:4:18: error: expected primary-expression before ‘int’
std::unique_ptr<int> p_int(new int(3));
^
main.cc:4:18: error: expected ‘;’ before ‘int’
$ g++ main.cc -std=c++11 // this is ok
如果您想在文档加载后运行它..没有更改事件,您可以使用
$('select').on('change',function(){
alert($(this).find('option:selected').index());
});
答案 1 :(得分:-1)
我知道这个问题要求jQuery,但是这里是如何使用纯Javascript获取它:
HTML:
<select id="sel">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
JS:
var index = document.getElementById('sel').selectedIndex;