问题
when my page loads very first time i see the watermark on the textbox but if any postback on the page, the watermark is cleared, is there a way to hold that watermark on the textbox?
<head runat="server">
<title></title>
<script src="scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="scripts/jquery.watermark.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#txtEmail").watermark("Email Address");
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtEmail" ErrorMessage="Email Invalid"></asp:RequiredFieldValidator>
</div>
</form>
</body>
回答1:
- go to the Scripts section in Firebug.
- select your HTML file in the drop-down.
- add a breakpoint on the line $("txtEmail").watermark.
- Debug using the console (check that the selector is successful, etc)
回答2:
//for jquery ready
$(function () {
$("#<%= txtEmail.ClientID %>").watermark("Email Address");
});
//for partial postbacks
function pageLoad()
{
$("#<%= txtEmail.ClientID %>").watermark("Email Address");
}
来源:https://stackoverflow.com/questions/10308074/watermark-textbox-cleared-on-partial-postback