【问题标题】:How to pass the string value to the function with a html string如何使用html字符串将字符串值传递给函数
【发布时间】:2019-09-11 06:53:45
【问题描述】:

我将一个前导零的订单id传递给函数,但在函数中,参数总是转换为没有前导零的数字,我该怎么办?

formatter:function(value, row, index) {
    return "<a href='javascript:listGoods("+'09100089'+")'><i class='fa fa-search-plus' /></a>";
                }

function listGoods(id) {
    jp.openViewDialog("goodInfo", "${ctx}/order/order/goods?id=" + id, "800px", "500px");
  }

【问题讨论】:

  • 请提供更多信息,说明您面临的问题以及您的预期结果。
  • 您的问题没有提供足够的信息,但可能是以下链接解决您的问题为什么 javascript parseInt 忽略字符串中的前导零? stackoverflow.com/questions/35238701/…

标签: javascript


【解决方案1】:

您的问题是您将参数作为数字而不是字符串传递。解决方案如下所示:

formatter:function(value, row, index) {
    return "<a href='javascript:listGoods(`"+'09100089'+"`)'><i class='fa fa-search-plus' /></a>";
  }

function listGoods(id) {
    jp.openViewDialog("goodInfo", "${ctx}/order/order/goods?id=" + id, "800px", "500px");
  }

这是另一个例子:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>


<script>
    function addButton() {
        document.body.innerHTML = "<button onclick='showMeParameter(`" + "09100089" + "`)'>my button</button>";
    }

    function showMeParameter(id) {
        alert(id);
    }

    addButton();
</script>
</body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 2015-06-03
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    相关资源
    最近更新 更多