1

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 调用背后的脚本有效。我已经回应了结果。

4

3 回答 3

3

此行无效:

$('#admin_student_school_select').change('click',function(){

它是什么,一个click或一个change事件?!


更新:

$(this+':selected')不是一个有效的选择器...使用这个:

var school_student = $(':selected', this).attr('school_student');
于 2012-04-09T05:10:18.120 回答
2

我认为$(this+':selected')不会返回任何有用的东西。

尝试:

$('#admin_student_school_select').change(function(){
   var school_student = $(':selected', this).attr('school_student');
   // rest of your code
});
于 2012-04-09T05:11:04.657 回答
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>
于 2012-04-09T05:20:28.903 回答