JQuery is not running
I am using master page and content page. In content page I am using following jquery code
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript" src="jquery-1.4.1.js"></script>
<script type="text/javascript">
$("document").ready(function() {
var y = $("#<%hid.ClientID%>").val();
});
</script>
</asp:Content>
<input type="hidden" id="hid" runat="server" />
When I run this code I am getting this error
Compiler Error Messa开发者_开发知识库ge: CS1002: ; expected
Line 167: @__w.Write("\").val();\r\n });\r\n </script>\r\n\r\n\r\n");
Any solution ?
It is an ASP.NET compiler error message. You're missing an =
from your output tag. It should be:
<%=hid.ClientID%>
Not sure if this is your problem, but document does not have to be in quotes
$(document).ready(function() {
You could simply call
$(function() {
var y = $("#hid").val();
});
if your input has a static id
.
You should verify your resulting HTML / JavaScript code and see what <%hid.ClientID%>
outputs.
This is an ASP.NET parsing error. The problem lies in the following line:
$("#<%hid.ClientID%>").val();
You see, the <%= %>, not <% %>. So, it should look like this:
$("#<%= hid.ClientID %>").val();
Right code is
var y = $('#<%=hid.ClientID%>').val();
#
Tells jquery that find a control with given ID and <%=hid.ClientID%>
gives the exact ID
. Only <%=hid.ClientID%>
this will not work. '#<%=hid.ClientID%>'
is the right code.
精彩评论