开发者

why is css not being applied to this jquery anchor button?

I must be missing something very basic in the CSS. My jQuery anchor button is functional, but it's rendering as a simple underlined label, not asa rounded-corner UI button. I would be grateful if someone could point out the error in this simple example.

Thanks

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//开发者_高级运维EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML LANG="en-US">
<HEAD>
<TITLE>button test</TITLE>

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Expires" content="Sat, 22 May 2010 00:00:11 GMT">
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<SCRIPT type="text/javascript">


$(document).ready(

    function() {

        $('a','.test').click(function(){showIntro();return false;});

     });


function showIntro()
{   
   document.location.href="intro.htm";  
}


</script>

<body>

<div class='test'><a href="#">Button</a></div>
</body>
</html>


You need to actually make it a button using .button(), like this:

$(function() {
  $(".test a").button();
});

You can see the jQuery UI demos here and a demo of your markup working here.


You need to add the proper class to the link, using jQuery or otherwise.

Try:

<a href="#" class="ui-button">Button</a>


You do not need to make it a button you just need

  $(".test a").click(function(){showIntro();return false;});

What you are trying to do with your selector passing the second paramater is the Scope. The second paramater is not mean to be a string (selector) it should be a jQuery Object.

So if you wanted to do it your way your would have to say

var test = $('.test');

$('a',test).click...

But the 1st method is prefered over doing it this way.


Sorry to be providing an answer, if not "the" answer, to my own question, but I have discovered a clue as to what's going on, if not the ultimate cause of the behavior. Below is code cut and pasted from the Button example on the jQuery website; take it to jsFiddle and run it: it works. But if you remove this line relating to the input-button:

 $("button, input:submit, a", ".demo").button();

then the anchor-button fails to render properly. Why is the anchor-element's rendering dependent on the existence of the input-button?

<script type="text/javascript">
    $(function() {
        $("button, input:submit, a", ".demo").button();

        $("a", ".demo").click(function() { return false; });
    });
    </script>
    <style>

    </style>



<div class="demo">

    <button>A button element</button>

    <input type="submit" value="A submit button">

    <a href="#">An anchor</a>

</div><!-- End demo -->

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜