jQuery enable/disable show/hide button w/ SELECT options. Get remaining option values

后端 未结 4 1859
半阙折子戏
半阙折子戏 2021-01-23 05:05

I have a select list which is being populated using the values from a text field. I also have two buttons: an add button which adds the entered value to the select list and a re

4条回答
  •  花落未央
    2021-01-23 05:58

    If I understand the problem correctly, I think you want to change this:

    // Add charge amount
    $('#addedchargeamtid option:selected').focus(function() {
       $('#removeButton').show();
    });
    

    to this:

    // Add charge amount
    $('#addedchargeamtid option').focus(function() {
       $('#removeButton').show();
    });
    

    so that the event handler gets added to all the select's options, not just the currently selected one when the code executes. And also make sure you're setting up this handler for any newly-created items, as well.

提交回复
热议问题