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中的2个DropDownList中进行更改后才可见_Javascript_Asp.net - Fatal编程技术网

如何将按钮设置为仅在我在javascript中的2个DropDownList中进行更改后才可见

如何将按钮设置为仅在我在javascript中的2个DropDownList中进行更改后才可见,javascript,asp.net,Javascript,Asp.net,在aspx文件中,我有 <asp:DropDownList ID="DropDownList1" runat="server" > </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server"> </asp:DropDownList> <asp:Button ID="load_data" runat="server" Text="<%$ Resources

在aspx文件中,我有

<asp:DropDownList ID="DropDownList1" runat="server" >
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<asp:Button ID="load_data" runat="server" Text="<%$ Resources : load_data %>"  
    onclick="load_data_class_Click" Visible="False"/>
现在,我想将按钮设置为只有在javascript中的2个DropDownList中进行更改后才可见

如何执行此操作?

您可以选择一个值为0的隐藏元素,每当有人更改下拉列表时,增加此隐藏元素的值,当它达到等于2时,然后显示按钮

function showButton(){
  //out of <option value="3"> This is 3rd </option> you get:
  var selected1text = ddl1.option[ddl.selectedIndex].text; // returns: This is 3rd
  var selected1value = ddl1.option[ddl.selectedIndex].val; // returns: 3

  //out of <option value="75"> This is 75th </option> you get:
  var selected2text = ddl2.option[dd2.selectedIndex].text; // returns: This is 75th
  var selected2value = ddl2.option[dd2.selectedIndex].val; // returns: 75

  if(
    selected1text != "" &&
    selected1value != "" &&
    selected2text != "" &&
    selected2value != ""
  ){
    //Our select lists all have values. We can show our button now.

    //if you use visibility:hidden;
    document.getElementById('load_data').style.visibility='visible';

    //if you use display:none;
    document.getElementById('load_data').style.display='block';
  }else{
    //don't do anything.
  }
}
基本上,您需要在两个下拉列表的更改事件上调用一个函数,该函数将执行上述操作

您可以选择一个值为0的隐藏元素,每当有人更改下拉列表时,增加该隐藏元素的值,当该值等于2时,显示该按钮

function showButton(){
  //out of <option value="3"> This is 3rd </option> you get:
  var selected1text = ddl1.option[ddl.selectedIndex].text; // returns: This is 3rd
  var selected1value = ddl1.option[ddl.selectedIndex].val; // returns: 3

  //out of <option value="75"> This is 75th </option> you get:
  var selected2text = ddl2.option[dd2.selectedIndex].text; // returns: This is 75th
  var selected2value = ddl2.option[dd2.selectedIndex].val; // returns: 75

  if(
    selected1text != "" &&
    selected1value != "" &&
    selected2text != "" &&
    selected2value != ""
  ){
    //Our select lists all have values. We can show our button now.

    //if you use visibility:hidden;
    document.getElementById('load_data').style.visibility='visible';

    //if you use display:none;
    document.getElementById('load_data').style.display='block';
  }else{
    //don't do anything.
  }
}

基本上,您需要在两个下拉列表的更改事件上调用一个函数,该函数将执行上述操作

将不会为Visible属性设置为False的ASP.NET控件生成标记。您需要通过JavaScript代码应用CSS显示:无或可见性。

不会为Visible属性设置为False的ASP.NET控件生成标记。您需要通过JavaScript代码应用CSS display:none或visibility。

第一个问题是您不能使用Visible=false,您需要使用CSS并设置visibility:hidden;,或显示:无

完成后,您可以执行以下操作->

获取列表的ID:

//id #1
var ddl1 = document.getElementById("DropDownList1");

//id #2
var ddl2 = document.getElementById("DropDownList2");
现在,我们需要创建一个onChange函数来获取这些值,并测试它们是否为空,如果不是,则显示按钮

function showButton(){
  //out of <option value="3"> This is 3rd </option> you get:
  var selected1text = ddl1.option[ddl.selectedIndex].text; // returns: This is 3rd
  var selected1value = ddl1.option[ddl.selectedIndex].val; // returns: 3

  //out of <option value="75"> This is 75th </option> you get:
  var selected2text = ddl2.option[dd2.selectedIndex].text; // returns: This is 75th
  var selected2value = ddl2.option[dd2.selectedIndex].val; // returns: 75

  if(
    selected1text != "" &&
    selected1value != "" &&
    selected2text != "" &&
    selected2value != ""
  ){
    //Our select lists all have values. We can show our button now.

    //if you use visibility:hidden;
    document.getElementById('load_data').style.visibility='visible';

    //if you use display:none;
    document.getElementById('load_data').style.display='block';
  }else{
    //don't do anything.
  }
}
然后,在下拉列表中,可以添加onChange=showButton


应该有用

第一个问题是不能使用Visible=false,需要使用CSS并设置visibility:hidden;,或显示:无

   I solved the problem with jquery

  $(document).ready(function () {


             $('#load_data').live('click', function () {

                 var result;
                 if (($('#DropDownList1 option:selected').val() != '') &&
                     ($('#DropDownList2 option:selected').val() != '') &&
                      ($('#DropDownList3 option:selected').val() != '')) {
                     //result = true;
                     alert("true");
                     result = true;
                 } else {
                     //  result= false;
                     alert("false");
                     result = false;
                 }
                 return result;
             });
         });
完成后,您可以执行以下操作->

获取列表的ID:

//id #1
var ddl1 = document.getElementById("DropDownList1");

//id #2
var ddl2 = document.getElementById("DropDownList2");
现在,我们需要创建一个onChange函数来获取这些值,并测试它们是否为空,如果不是,则显示按钮

function showButton(){
  //out of <option value="3"> This is 3rd </option> you get:
  var selected1text = ddl1.option[ddl.selectedIndex].text; // returns: This is 3rd
  var selected1value = ddl1.option[ddl.selectedIndex].val; // returns: 3

  //out of <option value="75"> This is 75th </option> you get:
  var selected2text = ddl2.option[dd2.selectedIndex].text; // returns: This is 75th
  var selected2value = ddl2.option[dd2.selectedIndex].val; // returns: 75

  if(
    selected1text != "" &&
    selected1value != "" &&
    selected2text != "" &&
    selected2value != ""
  ){
    //Our select lists all have values. We can show our button now.

    //if you use visibility:hidden;
    document.getElementById('load_data').style.visibility='visible';

    //if you use display:none;
    document.getElementById('load_data').style.display='block';
  }else{
    //don't do anything.
  }
}
然后,在下拉列表中,可以添加onChange=showButton


应该有用

当下拉列表值更改时,您可以添加类,每次更改时,您都会查看另一个下拉列表是否具有该类,然后为您的按钮设置visible true!当下拉列表值更改时,您可以添加类,每次更改时,您都会查看另一个下拉列表是否具有该类,然后为您的按钮设置visible true!
   I solved the problem with jquery

  $(document).ready(function () {


             $('#load_data').live('click', function () {

                 var result;
                 if (($('#DropDownList1 option:selected').val() != '') &&
                     ($('#DropDownList2 option:selected').val() != '') &&
                      ($('#DropDownList3 option:selected').val() != '')) {
                     //result = true;
                     alert("true");
                     result = true;
                 } else {
                     //  result= false;
                     alert("false");
                     result = false;
                 }
                 return result;
             });
         });