Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 简单的if/else点击功能_Javascript_Jquery_If Statement - Fatal编程技术网

Javascript 简单的if/else点击功能

Javascript 简单的if/else点击功能,javascript,jquery,if-statement,Javascript,Jquery,If Statement,我试图将if-else语句添加到下面的函数中 else语句将包含以下代码,以便在未单击按钮时,不仅隐藏颜色更新,同时禁用颜色更新 $("#color_update").prop('disabled', true); 这是代码函数: JS CSS HTML 请引导我。谢谢。据我所知,您希望在单击按钮时禁用/启用两个select元素之一。 这是同样的理由 本质上,我们可以使用任意一个select元素的disabled属性作为决定因素 $("#color_update").prop('dis

我试图将if-else语句添加到下面的函数中

else语句将包含以下代码,以便在未单击按钮时,不仅隐藏颜色更新,同时禁用颜色更新

$("#color_update").prop('disabled', true);
这是代码函数:

JS

CSS

HTML


请引导我。谢谢。

据我所知,您希望在单击按钮时禁用/启用两个select元素之一。 这是同样的理由

本质上,我们可以使用任意一个select元素的disabled属性作为决定因素

    $("#color_update").prop('disabled', true); // Disable the select box initially
    $("#color_update").hide(); // Also hide it

    $('#update').click(function() {
      if ($('#color_update').prop('disabled') == true) { // We check the 'disabled' property to determine our next step

        // The button is now disabled, we need to enable it and hide the #color select 
        $("#color_update").prop('disabled', false);
        $("#color").prop('disabled', true);

        // We can now show and hide the respective select elements
        $("#color_update").show();
        $("#color").hide();
      } else { // We can now handle the other case
        $("#color_update").prop('disabled', true);
        $("#color").prop('disabled', false);

        $("#color_update").hide();
        $("#color").show();
      }
    });
如果你还需要什么,一定要告诉我


编辑:更新了JSFIDLE链接

您想要什么?最初是否要禁用颜色更新?open函数与这个问题有多大关系?什么时候调用open?当前代码段中没有where??我想将if-else语句添加到$'update'。clickfunctionevent{.color_更新从一开始就被禁用,只有在单击更新按钮时才启用@Satpal@Mint,请详细说明。请清楚地说明如果单击更新按钮,if条件将禁用颜色,else条件将禁用颜色更新。我知道,打开的函数隐藏并显示颜色更新。我希望颜色更新不仅被隐藏,而且同时被禁用。@Mayank Raj这正是我要找的。谢谢@MayankRaj@Mint,很乐意提供帮助。继续黑客攻击:
#color_update {
display: none;
}
<select id="color">
      <option value="Red">Red</option>
      <option value="Green">Green</option>
      <option value="Blue">Blue</option>
    </select>

    <input type="button" id="update" value="Update" />

    <select id="color_update">
      <option value="Red">Black</option>
      <option value="Green">Purple</option>
      <option value="Blue">White</option>
    </select>
    $("#color_update").prop('disabled', true); // Disable the select box initially
    $("#color_update").hide(); // Also hide it

    $('#update').click(function() {
      if ($('#color_update').prop('disabled') == true) { // We check the 'disabled' property to determine our next step

        // The button is now disabled, we need to enable it and hide the #color select 
        $("#color_update").prop('disabled', false);
        $("#color").prop('disabled', true);

        // We can now show and hide the respective select elements
        $("#color_update").show();
        $("#color").hide();
      } else { // We can now handle the other case
        $("#color_update").prop('disabled', true);
        $("#color").prop('disabled', false);

        $("#color_update").hide();
        $("#color").show();
      }
    });