开发者

Jquery Anchor Button doesn't apply css in ASP .net

开发者 https://www.devze.com 2023-04-09 23:11 出处:网络
all, I follow the example of Jquery ui button and translated the html code to asp.net as follows enter code here

all, I follow the example of Jquery ui button and translated the html code to asp.net

as follows

enter code here
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<link rel="Stylesheet" type="text/css" href="CSS/jquery.ui.all.css" />
<script type="text/javascript" src="Script/jquery-1.6.2.js"></script>
<script type="text/javascript" src="Script/jquery.ui.button.js"></script>
<script type="text/javascript" src="Script/jquery.ui.core.js"></script>
<script type="text/javascrip开发者_运维技巧t" src="Script/jquery.ui.widget.js"></script>
</head>
<body>
<form runat="server">
<div class="demo">
    <a href="#" class="demo">An anchor</a>
</div>
</form>
<script type="text/javascript">
    $(function () {
        $("a", ".demo").button();
        $("a", ".demo").click(function () { return false; });
    });
</script>
</body>
</html>

however the css of the anchor button doesn't show, which mean the anchor shows a link just as before, doesn't anyone know why this happens?


First use Chrome or Firefox with Firebug. Save your page without your JavaScript, open up the console and put in

$("a", ".demo")

Just the ensure nothing's gone really wrong and that the selector is returning the proper element. If this doesn't work make sure your jQuery is properly referenced.

After that put in

$("a", ".demo").button();

Now check the link element in the inspector and check that the DOM has been changed (it should now be a span in an a in a div). At this point if it failed double check your references for jQueryUI.

If that worked but it isn't showing properly your CSS isn't referenced correctly.

Edit based on comment

Your JS references are in the wrong order. Core needs to come first, then widget, then button. Otherwise each file is trying to use functions that don't yet exist.

The best way would be to just reference jQueryUI from a CDN (larger but likely to be cached) or build a custom jQueryUI file from the site rather than including the individual files, this way you won't get these problems.


Maybe it should be:

$(function () {
    $("a.demo").button();
    $("a.demo").click(function () { return false; });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号