读书人

JS自定义属性的有关问题

发布时间: 2012-06-07 15:05:14 作者: rapoo

JS自定义属性的问题
大家好, 我最近刚开始学JQuery, 觉得它的事件什么的挺方便的, 但是我现在遇到一个问题, 就是假设我有一列的button, CSS类都一样, 我自定义了一个index属性, 用来区别这些button, 我在JQuery里面该怎么写函数才能用一个函数处理这一列button的click事件呢?

[解决办法]
根本不需要自定义个index属性

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script><script type="text/javascript">$(document).ready( function() {    $("div.TileItem").mouseover( function() {        alert($(this).index());    });});</script></head><body><div class="TileItem">...</div><div class="TileItem">...</div><div class="TileItem">...</div></body></html>
[解决办法]
楼主 如果你真把 w3school 里介绍的jquery看完了 ,那么连这个都不会做的话,真应该多看几遍 或者 考虑下换个行业之类的。。。慢慢学 不要着急。

参考下吧

HTML code
<!DOCTYPE HTML><html>    <head>        <meta charset="gb2312" />        <title></title>            <script src="http://code.jquery.com/jquery-latest.js"></script>    </head>    <body>        <div class="TileItem" index="0">...</div>        <div class="TileItem" index="1">...</div>        <div class="TileItem" index="2">...</div>        <script>            $('div').mouseover(function(){                $(this).css('border', '1px solid red');            }).mouseout(function(){                $(this).css('border', '');            })        </script>    </body></html>
[解决办法]
探讨
大家好, 我最近刚开始学JQuery, 觉得它的事件什么的挺方便的, 但是我现在遇到一个问题, 就是假设我有一列的button, CSS类都一样, 我自定义了一个index属性, 用来区别这些button, 我在JQuery里面该怎么写函数才能用一个函数处理这一列button的click事件呢?

读书人网 >JavaScript

热点推荐