Issue with .change function in jQuery form

前端 未结 4 596
囚心锁ツ
囚心锁ツ 2021-01-24 15:57

I am working on a script that changes the span text value depending on user input in the select menu.

I have a fault with my current script. How do I fix it so when I cl

4条回答
  •  無奈伤痛
    2021-01-24 16:32

    You need to determine the selected option and then the text inside that option.

     $(function() {         
        $('#usertype').change(function() { 
            var selectedText = $("#usertype option[value='"+ $(this).val() +"']").text();
            $(this).next("span").text(selectedText);
        });     
    }); 
    

    Check out this jsfiddle JSFIDDLE

提交回复
热议问题