[急]js实现点击td里的按钮,这个td里增加一个小图片,点击另外一个按钮减少一个图片解决思路
[急]js实现点击td里的按钮,这个td里增加一个小图片,点击另外一个按钮减少一个图片
js如何实现点击表格td里的增加按钮,在按钮后边增加一个小图片,点击另外一个减少按钮,在减少按钮前边减少一个图片。并且有个隐藏控件来记录图片的个数。
必须在一个td里完成,求大侠帮助!!
基本的样子是:
<html >
<head>
<title>无标题文档</title>
</head>
<body>
<table>
<tr>
<td>
<input type="button" value="增加"/>
<img src="images/4.jpg"/>
<input type="button" value="减少"/>
<input type="hidden" value="" />
</td>
</tr>
</table>
</body>
</html>
------解决方案--------------------
js如何实现点击表格td里的增加按钮,在按钮后边增加一个小图片,点击另外一个减少按钮,在减少按钮前边减少一个图片。并且有个隐藏控件来记录图片的个数。
必须在一个td里完成,求大侠帮助!!
基本的样子是:
<html >
<head>
<title>无标题文档</title>
</head>
<body>
<table>
<tr>
<td>
<input type="button" value="增加"/>
<img src="images/4.jpg"/>
<input type="button" value="减少"/>
<input type="hidden" value="" />
</td>
</tr>
</table>
</body>
</html>
------解决方案--------------------
- 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 runat="server"> <script src="JS/jquery-1.4.1.js" type="text/javascript"></script> </head> <body> <table> <tr> <td> <input type="hidden" value="0" id="count" /> <input type="button" value="增加" id="add" /> <input type="button" value="减少" id="reduce" /> </td> </tr> </table> <script type="text/javascript"> $("#add").bind("click", function () { $(this).after("<img src='Images/4.jpg'>"); var count = $("#count").val(); $("#count").val(parseInt(count) + 1); }); $("#reduce").bind("click", function () { if ($(this).prev("img")[0]) { var count = $("#count").val(); $("#count").val(parseInt(count) - 1); } $(this).prev("img").remove(); }); </script> </body> </html>