admin管理员组

文章数量:1287514

I'm looking for a good 10 minute introduction to Unobtrusive Javascript using JQuery. I'm pletely new to the concept, and I'd like to see how the event binding and such works.

As some background, I'm looking to do a "remove this tag" system similar to what we have here on SO. Looking at the source, I didn't see any js, just an img tag. That makes me think there must be external js that's binding to the click event. I want to know how to do that, and I want a tutorial that shows me how!

I'm looking for a good 10 minute introduction to Unobtrusive Javascript using JQuery. I'm pletely new to the concept, and I'd like to see how the event binding and such works.

As some background, I'm looking to do a "remove this tag" system similar to what we have here on SO. Looking at the source, I didn't see any js, just an img tag. That makes me think there must be external js that's binding to the click event. I want to know how to do that, and I want a tutorial that shows me how!

Share Improve this question edited Jul 21, 2012 at 13:28 Mike Pennington 43.1k21 gold badges139 silver badges188 bronze badges asked Nov 3, 2008 at 19:12 MicahMicah 17.8k8 gold badges42 silver badges48 bronze badges 3
  • looks like a whole slew of them here: docs.jquery./Tutorials – Adam Alexander Commented Nov 3, 2008 at 19:19
  • 1 I recently found a nice article on non obtrusive javascript with jQuery by Simon Willison. – nivcaner Commented Feb 9, 2009 at 11:52
  • 1 Try this: railscasts./episodes/205-unobtrusive-javascript – Rahul Commented Aug 25, 2011 at 11:44
Add a ment  | 

1 Answer 1

Reset to default 10

I guess the Tutorials page on jQuery homepage would be a good place to start :)

Simple example to remove a link you have clicked on follows:

<html>

<head>
<script type="text/javascript"
  src="http://ajax.googleapis./ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
    // execute script only when DOM has finished loading
    $(document).ready(function() {
        $('#removeme').click(function() {
            // remove element that has been target of the event
            $(this).remove();
            // stop browser from following the link
            return false;
        });
    });
</script>
</head>

<body>
  <p>
    <a id="removeme" href="http://example">Remove me</a>
  </p>
</body>
</html>

本文标签: Unobtrusive javascript with jquerygood 10 minute tutorialStack Overflow