首先引入js文件:<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
一般的對於
<asp:Label ID="lbDepartName" runat="server" ClientIDMode="Static"></asp:Label>
<script type="text/javascript"> $(document).ready(function() { var test=$("#lbDepartName").attr("innerText");
//或者var test=$("#lbDepartName").html(); 等等
alert(test);
});
</script>
但是對於
<asp:Label ID="lbDepartName" runat="server" ClientIDMode="Static" Visible="false"></asp:Label>
由於在服務器端被隱藏,所以jquery不能獲取到它的內容,采用css來隱藏就可以了
<style type="text/css"> .hide-box{display:none;} <style>
<asp:Label ID="lbDepartName" runat="server" ClientIDMode="Static" CssClass="hide-box"></asp:Label>