如何使用html字符串将字符串值传递给函数

时间:2019-09-11 06:53:45

标签: javascript

我将带有前导零的订单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");
  }

1 个答案:

答案 0 :(得分:0)

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

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>