JavaScript setVaria可以成为功能
我有一个工具栏,该工具栏具有4个值,在页面加载后需要分配。 电话,联系人,反馈,聊天
前三个是数据元素,这些数据元素正常,但是第四chat
需要不同的基于用户区域的不同。
因此,我的功能是一个开关语句
const handleChatClick = (e) => {
console.log('handle chat click fired')
switch(customerCountry) {
case('US'):
case('CA'):
case('PR'): {
triggerChat('NAM');
}
,我正在使用setVariable
分配所有内容,
toolbarOnThePage.setAttribute('phone', `${phoneNumberVariable}`);
toolbarOnThePage.setAttribute('contactus', `${contactUsVariable}`);
toolbarOnThePage.setAttribute('feedback', `${feedbackVariable}`);
toolbarOnThePage.setAttribute('chat', `${handleChatClick()}`);
但是这将分配chat
作为我函数的字符串版本。我尝试了我能想到的每种组合:$ {()=> HandleChatClick()}
HandlechatClick()
$ {HandlechatClick}
HandlechatClick
如何将属性设置为函数?
I have a toolbar that has 4 values that need to be assigned after the page loads. phone, contactus, feedback, chat
The first three are data elements that are being assigned just fine but the forth chat
needs to be different based of off the user's region.
So I have a function that is a switch statement
const handleChatClick = (e) => {
console.log('handle chat click fired')
switch(customerCountry) {
case('US'):
case('CA'):
case('PR'): {
triggerChat('NAM');
}
And I am assigning everything with setVariable
toolbarOnThePage.setAttribute('phone', `${phoneNumberVariable}`);
toolbarOnThePage.setAttribute('contactus', `${contactUsVariable}`);
toolbarOnThePage.setAttribute('feedback', `${feedbackVariable}`);
toolbarOnThePage.setAttribute('chat', `${handleChatClick()}`);
However this will assign chat
to be a string version of my function. I have tried every combination I can think of:${() => handleChatClick()}
handleChatClick()
${handleChatClick}
handleChatClick
How can I set the attribute to be a function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论