操作自動生成的html表格裡 對文字框加一減一的例子
阿新 • • 發佈:2019-01-24
JQuery操作html表格 對文字框加一減一的例子 無ID標識之類
<script type="text/javascript"> function calc(obj, val) { var $input = $($(obj).parent().parent().find("input").eq(0)); var tbVal = parseInt($input.val()); $input.val(tbVal + val); //var tbVal = parseInt($input.textbox('getValue')); //easyui-textbox方式 //$input.textbox('setValue', tbVal + val); } </script> <table> <tr> <td> <input type="text" value="0" /> @* <input class="easyui-textbox" value="0" />*@ </td> <td> <input type="button" onclick="calc(this, 1)" value="+" /><input type="button" onclick=" calc(this, -1)" value="-" /> </td> </tr> <tr> <td> <input type="text" value="0" /> </td> <td> <input type="button" onclick="calc(this, 1)" value="+" /><input type="button" onclick=" calc(this, -1)" value="-" /> </td> </tr> <tr> <td> <input type="text" value="0" /> </td> <td> <input type="button" onclick="calc(this, 1)" value="+" /><input type="button" onclick=" calc(this, -1)" value="-" /> </td> </tr> </table>