我的页面上有一组动态生成的下拉框.基本上我用jQuery克隆它们.现在我想捕获更改事件的每个下拉列表中选择的值.
我试过这样的东西,但是没用.
$('._someDropDown').live('change', function(e) {
//debugger;
var v = $(this);
alert($(this + ':selected').val());
alert($(this).val());
});
Run Code Online (Sandbox Code Playgroud)
我该如何完成?
Rob*_*zvi 97
获取所选选项的文本
$("#your_select :selected").text();
Run Code Online (Sandbox Code Playgroud)
获取所选选项的值
$("#your_select").val();
Run Code Online (Sandbox Code Playgroud)
Oli*_*cal 62
这就是你需要的:)
$('._someDropDown').live('change', function(e) {
console.log(e.target.options[e.target.selectedIndex].text);
});
Run Code Online (Sandbox Code Playgroud)
对于新的jQuery使用 on
$(document).on('change', '._someDropDown', function(e) {
console.log(this.options[e.target.selectedIndex].text);
});
Run Code Online (Sandbox Code Playgroud)
小智 15
$("#citiesList").change(function() {
alert($("#citiesList option:selected").text());
alert($("#citiesList option:selected").val());
});
Run Code Online (Sandbox Code Playgroud)
citiesList是select标签的id
检查出来 - >
获取文字
$("#selme").change(function(){
$(this[this.selectedIndex]).text();
});
Run Code Online (Sandbox Code Playgroud)
为了获得价值
$("#selme").change(function(){
$(this[this.selectedIndex]).val();
});
Run Code Online (Sandbox Code Playgroud)