Javascript JS更改选择选项时隐藏按钮

Javascript JS更改选择选项时隐藏按钮,javascript,jquery,onchange,Javascript,Jquery,Onchange,我有简单的表格: <form action=""> <select name="gender" onchange="myFunction()"> <option value="m">male</option> <option value="f">female</option> </select> <input type="hidden" name="u

我有简单的表格:

<form action="">
    <select name="gender" onchange="myFunction()">
        <option value="m">male</option>
        <option value="f">female</option>
    </select>
    <input type="hidden" name="user_id" value="1">
    <input type="submit" id="save1" value="Save">
</form>

<form action="">
    <select name="gender" onchange="myFunction()">
        <option value="m">male</option>
        <option value="f">female</option>
    </select>
    <input type="hidden" name="user_id" value="2">
    <input type="submit" id="save2" value="Save">
</form>
只有在选择(‘性别’)更改了每个用户(表单)的选项时,我才想隐藏“保存”按钮

问题是,当我更改用户2的性别时,用户1的按钮将隐藏

注意:有许多表单和用户

请尝试以下操作:

$("select").change(function() {
  $(this).parent("form").find("input[type='submit']").hide();
});
$("select").on("change", function() {
    $(this).parent().children('input[type=submit]').hide();
});
试试这个:

$("select").change(function() {
  $(this).parent("form").find("input[type='submit']").hide();
});
$("select").on("change", function() {
    $(this).parent().children('input[type=submit]').hide();
});
试试这个:

$("select").change(function() {
  $(this).parent("form").find("input[type='submit']").hide();
});
$("select").on("change", function() {
    $(this).parent().children('input[type=submit]').hide();
});
工作

尝试以下方法:

$("select").change(function() {
  $(this).parent("form").find("input[type='submit']").hide();
});
$("select").on("change", function() {
    $(this).parent().children('input[type=submit]').hide();
});
像这样工作:

$('form>select').change(function(e){
    $(e.currentTarget).siblings("input[type='submit']").hide();
});
或者像这样:

$('form>select').change(function(e){
    $(e.currentTarget).siblings("input[type='submit']").hide();
});

您应该使用jquery,在表单上绑定操作,在“选择”框上触发,然后使用同级查找表单中的按钮。 例如:

$('form').on('change', 'select', function() {
    var condition = ($(this).val() && $(this).val() != ""); // true : show button, false : hide button
         $(this).siblings('input[type="submit"]').toggle(condition);
})

您应该使用jquery,在表单上绑定操作,在“选择”框上触发,然后使用同级查找表单中的按钮。 例如:

$('form').on('change', 'select', function() {
    var condition = ($(this).val() && $(this).val() != ""); // true : show button, false : hide button
         $(this).siblings('input[type="submit"]').toggle(condition);
})
试试这个:-

试试这个:-


无效的标记。
id的
不能重复。请为两个按钮指定不同的id,它将work@Kartikeya说得好。改变。我是按功能创建表单的。请提供一个提琴,以便我们仔细查看此事。“我想隐藏“保存”按钮,仅当选择(‘性别’)更改了每个用户(表单)的选项时。”当所有选择选项都更改时,是否要隐藏所有按钮?还是只隐藏该选择的按钮?哪些更改?标记无效。
id的
不能重复。如果为两个按钮指定不同的id,则会work@Kartikeya说得好。改变。我是按功能创建表单的。请提供一个提琴,以便我们仔细查看此事。“我想隐藏“保存”按钮,仅当选择(‘性别’)更改了每个用户(表单)的选项时。”当所有选择选项都更改时,是否要隐藏所有按钮?还是只隐藏该选择的按钮?哪些更改?