jQuery在下拉菜单中找不到我的自定义属性我有一个类似于它的上面一行很好,但是这一直给我一个未定义的。
的jQuery
$('#admin_student_school_select').change('click',function(){
var school_student = $(this+':selected').attr('school_student');
$('#admin_student_content_details')
.html(ajax_load)
.load(loadUrl,"form_being_submitted=admin_page_list_student&school="+school_student);
});
HTML
<select id="admin_student_school_select">
<option>Select a School</option>
<option school_student="1">Riverside Community College</option>
<option school_student="2">Victor Valley College</option>
<option school_student="3">Cal State San Bernardino</option>
<option school_student="4">Craffton College</option>
<option school_student="5">San Bernardino Community</option>
</select>
ajax调用背后的脚本有效。我已经回应了结果。
答案 0 :(得分:3)
此行无效:
$('#admin_student_school_select').change('click',function(){
什么是click
或change
事件?!
<强>更新强>
$(this+':selected')
不是有效的选择器...请使用:
var school_student = $(':selected', this).attr('school_student');
答案 1 :(得分:2)
我认为$(this+':selected')
不会返回任何有用的东西。
尝试:
$('#admin_student_school_select').change(function(){
var school_student = $(':selected', this).attr('school_student');
// rest of your code
});
答案 2 :(得分:0)
试试这个:
$('#admin_student_school_select').change(function(){
var school_student = $(this).val();
});
<select id="admin_student_school_select">
<option value="0">Select a School</option>
<option value="1">Riverside Community College</option>
<option value="2">Victor Valley College</option>
<option value="3">Cal State San Bernardino</option>
<option value="4">Craffton College</option>
<option value="5">San Bernardino Community</option>
</select>