谁能帮我把这段js代码改写成jQuery的,提高一下性能!!!
1.Event.observe(window,"load",function(){2.3.varthisSpending=document.getElementsByNa...
1.Event.observe(window, "load", function() {
2.
3. var thisSpending = document.getElementsByName("thisSpending");
4. var locator = document.getElementsByName("locator");
5. if (thisSpending.length !== 0) {
6. for (var i = 0, j = thisSpending.length; i < j; i++) {
7. var trObj = thisSpending[i].parentNode.parentNode.parentNode.parentNode;
8. for (var m = 0, n = locator.length; m < n; m++) {
9. if ((trObj.rowIndex - 1) == m) {
10. locator[m].value = parseInt(locator[m].value)
11. + parseInt(thisSpending[i].value);
12. var spanObj = locator[m].previousSibling;
13. spanObj.innerText = locator[m].value;
14. }
15. }
16. }
17. }
18.
19. Event.observe($("refreshBtId"), "click" , refreshAction);
20.});
21.
22.
23.function refreshAction(){
24. window.location.reload();
25.} 展开
2.
3. var thisSpending = document.getElementsByName("thisSpending");
4. var locator = document.getElementsByName("locator");
5. if (thisSpending.length !== 0) {
6. for (var i = 0, j = thisSpending.length; i < j; i++) {
7. var trObj = thisSpending[i].parentNode.parentNode.parentNode.parentNode;
8. for (var m = 0, n = locator.length; m < n; m++) {
9. if ((trObj.rowIndex - 1) == m) {
10. locator[m].value = parseInt(locator[m].value)
11. + parseInt(thisSpending[i].value);
12. var spanObj = locator[m].previousSibling;
13. spanObj.innerText = locator[m].value;
14. }
15. }
16. }
17. }
18.
19. Event.observe($("refreshBtId"), "click" , refreshAction);
20.});
21.
22.
23.function refreshAction(){
24. window.location.reload();
25.} 展开
2个回答
展开全部
<script type="text/javascript">
$(function () {
var thisSpending = $("*[name='thisSpending']");
var locator = $("*[name='locator']");
if (thisSpending.size() != 0) {
thisSpending.each(function (i) {
var trObj = $(this).parent().parent().parent().parent();
var t = $(this);
locator.each(function (j) {
if (i - 1 == j) {
$(this).val(parseInt($(this).val()) + parseInt(t.val()));
$(this).prev().text($(this).val());
}
});
});
}
$("#refreshBtId").click(refreshAction);
});
</script>
$(function () {
var thisSpending = $("*[name='thisSpending']");
var locator = $("*[name='locator']");
if (thisSpending.size() != 0) {
thisSpending.each(function (i) {
var trObj = $(this).parent().parent().parent().parent();
var t = $(this);
locator.each(function (j) {
if (i - 1 == j) {
$(this).val(parseInt($(this).val()) + parseInt(t.val()));
$(this).prev().text($(this).val());
}
});
});
}
$("#refreshBtId").click(refreshAction);
});
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询