showing and hiding a div using jquery and asp.net in the middle of screen
hi folks
I have this following code but it gives me "invalid argument" error when I click on the 'a tag'. what is my mistake ?<script type="text/javascript">
$(function () {
$('#click').click(function () {
$get('log').style.top = (screen.y / 2).toString();
$get('log').style.left = (screen.x / 2).toString();
$('#Log').show();
});
});
</script>
<a id="click">[to login click here]</a>
<div id="Log" style="display: none; position:absolute; top: -开发者_Python百科29px; left: 569px;">
<div style="text-align: center; vertical-align: middle; height: 316%;">
<asp:Login ID="Login1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderPadding="4"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em"
ForeColor="#333333" DestinationPageUrl="~/Account/Default.aspx" DisplayRememberMe="False">
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" />
<TextBoxStyle Font-Size="0.8em" />
<TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
</asp:Login>
</div>
</div>
why mix $get and $?
just using jquery you can set the top and left...
$('#log').css('top',(screen.y / 2).toString() + 'px');
and I hope your script isnt like that in the code, just before the html in the page? If it is, then move your scripts to the bottom before closing the </body>
tag.
Try wrapping your jQuery in this:
$(document).ready(function() { ... }
Also, are you importing the jQuery framework?
If you have downloaded it locally:
<script src="jquery.js" type="text/javascript"></script>
Using the current version of jQuery, I would do something along the following line:
$("#click").live("click", function() { ... });
instead of the .click
as that would allow it to bind as loaded. No need for the $(document).ready();
I think the best one was answered before.
精彩评论