Javascript 从HTML调用函数的优雅方式?
我有这样的想法:Javascript 从HTML调用函数的优雅方式?,javascript,html,scope,linter,Javascript,Html,Scope,Linter,我有这样的想法: 功能移除产品(dataProduct){ console.log(数据产品) } RemoveRemove使用函数removeProduct(but){var product=JSON.parse(but.getAttribute(“数据商店列表”);…}如果您有jQuery,您不需要JSON.parse,只需要$(this.data(“商店列表”).foo-但是,如果我很密集,那么最好在CodeReviewOrry上问这个问题,但是linter的问题是否与函数有关?如果可以
功能移除产品(dataProduct){
console.log(数据产品)
}
Remove
Remove
使用函数removeProduct(but){var product=JSON.parse(but.getAttribute(“数据商店列表”);…}
如果您有jQuery,您不需要JSON.parse,只需要$(this.data(“商店列表”).foo-但是,如果我很密集,那么最好在CodeReviewOrry上问这个问题,但是linter的问题是否与函数有关?如果可以,请将其更改为var removeProduct=function(dataProduct){console.log(dataProduct)}
,那么它将不起作用,因为函数正在使用另一个类的实例。创建如下函数:window.removeProduct=function(dataProduct)…。
@Cristy I read拥有全局函数不是很有效。在这种情况下,解决问题的唯一办法是什么?