简体   繁体   English

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

[英]How to pass the string value to the function with a html string

I'm pass a order id with leading-zero to function, but in the function, the parameter alway convert to number without leading-zero,What should I do? 我将带有前导零的订单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");
  }

Your problem is you pass your parameter as a number not as a string. 您的问题是您将参数作为数字而不是字符串传递。 The solution looks like this: 解决方案如下所示:

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");
  }

Here is another example: 这是另一个示例:

 <!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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM