我正在添加select
下拉列表和一个动态输入字段(当前已禁用)。我想知道,只要选择Others
选项,应该启用输入字段。这里是我的代码: -onchange select(动态)下拉列表
<div></div>
<button> Add</button>
</body>
<script type="text/javascript">
$(function(){
option_html = '<option value="Others">Others</option><option value="Others1">Others1</option>'
input_html = '<input placeholder="Other, if any" class="form-control input-md others_input" type="text" disabled="disabled">'
html = '<select class="form-control select_question" name="qa_">' + option_html + '</select>' + input_html
$('button').on('click', function(){
$("div").after(html);
})
$('select.select_question').on('change', function(){
alert(111)
$(this).closest(".others_input").prop('disabled', false);
})
})
</script>
我无法赶上onchange事件。 jsFiddle
能否请您提供的jsfiddle链接。这不是捕捉onchange事件。 “最接近”的 – PythonEnthusiast
在这里不起作用。您需要不同的选择器,因为这些元素是兄弟姐妹,而不是父子。 –
谢谢 - 已更改。 – mplungjan