首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想要简洁地修复代码。

我想要简洁地修复代码。
EN

Stack Overflow用户
提问于 2018-07-16 16:15:41
回答 0查看 68关注 0票数 0

var template是作为冗余使用的,我想知道如何修复它,以便您只能使用此部分一次

代码语言:javascript
复制
function pluscal(data) {
  var idx = index++
    var form = parseInt($("#plusstr1").val()) + $("#plus_op").text() + parseInt($("#plusstr2").val())
  var cal = parseInt($("#plusstr1").val()) + parseInt($("#plusstr2").val())
  var template = "<tr>" +
    "<td>" + idx + "</td>" +
    "<td>" + form + "</td>" +
    "<td>" + data.result + "</td>" +
    "<td><button class='ul icon button' id='remove_btn'><i class='trash alternate icon'></i></button></td>" +
    "</tr>"
  $("tbody").append(template)
}

代码语言:javascript
复制
function minuscal(data) {
  var idx = index++
    var form = parseInt($("#minusstr1").val()) + $("#minus_op").text() + parseInt($("#minusstr2").val())
  var cal = parseInt($("#minusstr1").val()) - parseInt($("#minusstr2").val())

  var template = "<tr>" +
    "<td>" + idx + "</td>" +
    "<td>" + form + "</td>" +
    "<td>" + data.result + "</td>" +
    "<td><button class='ul icon button' id='remove_btn'><i class='trash alternate icon'></i></button></td>" +
    "</tr>"
  $("tbody").append(template)
}
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51357372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档