【发布时间】:2017-03-27 19:44:04
【问题描述】:
我有以下 Javascript 函数
function CallOfferRenderAction(productCode, providerCode)
{
}
我正在尝试在点击时发送属性值,但出现错误:
Uncaught ReferenceError: offercode 未定义 在 HTMLInputElement.onclick
这是我发送属性值的方式。
<input type="button" value="View" class="viewbtn" onclick="CallOfferRenderAction(this.attr(offercode), this.attr(providercode))" offercode="ATT-COMP-DTV-PRM-ALL-INCL_SEPARATOR_ATT-COMP-HSIA-PLS-A" providercode="ATTv6">
我做错了什么?
【问题讨论】:
-
提供几个html内容,你在哪里设置你在html中使用的offercode和providercode。
-
offercode变量不在正在执行的 JS 的范围内。如果您打算将其包含为字符串,那么您会看到attr() is not a function因为这是一个 jQuery 方法,而this是一个原生元素 -
我认为你只需要用单引号将 offercode 和 providercode 括起来。
-
我只是将“this”传递给你的函数,然后从那里找出属性。
-
@DavidP 试过了,然后我得到了
Uncaught TypeError: this.attr is not a function at HTMLInputElement.onclick错误
标签: jquery html parameters attributes