2016-06-07 99 views
0

我试图做一个asp文本框/复选框组合,将隐藏文本框,如果复选框被选中,但我不能让jQuery/Javascript的工作。我已经尝试了许多不同的解决方案,并还没有得到它的工作,所以任何帮助,将不胜感激隐藏基于ASP复选框

ASP:

<div runat="server" id="editStartYear" class="productInfo"> 
    Edit Start Year: 
    <asp:CheckBox ID="startDateCheckBox" runat="server" ClientIDMode="Static" Text="Unknown Start Date"/> 
    <asp:TextBox runat="server" ID="startBox" ClientIDMode="Static" Width="150" placeholder="Start Year"></asp:TextBox> 
</div> 

的jQuery:

$(document).ready(function() { 

$('#searchIcon').hover(function() { 
    $('#searchIcon').attr("src", "includes/images/searchIconHover.png"); 
}, function() { 
    $('#searchIcon').attr("src", "includes/images/searchIcon.png"); 
}); 
$('#searchBox').focus(function() { 
    $('#searchBox').attr("value", ""); 
}); 

$("#startDateCheckBox").change(function() { 
     if (this.checked) { 
      $("#startBox").hide(); 
     } else { 
      $("#startBox").show(); 
     } 

}); 

}); 
+0

这个问题可以通过添加实际的HTML输出更好。 – nateyolles

回答

1

您可以在asp.net标记添加ClientIDMode="Static"为复选框和文本框。然后客户端JavaScript可以用来解决复选框。现在你有它作为服务器端控制。

$("#startDateCheckBox").change(function() { 
    if(this.checked) { 
     $("#startBox").hide(); 
    } else { 
     $("#startBox").show(); 
    } 

}); 
+0

我该如何调用这个函数?我应该把它放在document.ready中并摆脱onclick?现在与onclick它说ReferenceError:hideStartDiv没有定义 –

+0

你可以把它放在document.ready – pparas

+0

仍然没有运气得到这个工作 –

相关问题