javascript - 如何修复'setAttributeNode(att)'以添加属性副修改现有?
问题描述
我正在使用shinyJS
包以及shiny
标签和传统 HTML 将属性“标题”添加到现有元素。我可以在控制台(检查员 [Google CHROME])中毫无问题地执行此操作,但是当尝试通过 ui.R 或 server.R 应用相同的输入时,没有任何变化或实际文本值更改副标题(工具提示)。
如上所述,我尝试了以下方法:
shinyJS
: html()
shiny
: tags$HTML; tags$body(tags$script()) HTML:在 HTML 文件 (mychange.html) 中添加更改并从 www 采购
要修改的输入(添加工具提示)
pickerInput(
inputid = "ReqTabSel6",
label = '',
choices = c('Choice 1', 'Choice 2', 'Choice 3'),
mulitple = F,
options = list(
style = "btn-info"))
这是正确的功能(因为它在 Web 检查器下的控制台中运行时会更新):
var addToolTip1 = document.querySelector('#form>div:nth-child(10)>div>div>div>ul>li.selected>a')
var att = document.createAttribute("title");
att.value = "I am a tooltip title";
addToolTip1 .setAttributeNode(att);
然而,在 R...
闪亮的JS
server.R
...
observeEvent(input$ReqTabSel6, {
shinyJS::html(id = NULL,
html = "var addToolTip1 = document.querySelector('#form>div:nth-child(10)>div>div>div>ul>li.selected>a')
var att = document.createAttribute("title");
att.value = "I am a tooltip title";
addToolTip1 .setAttributeNode(att);",
selector = '#form>div:nth-child(10)>div>div>div>ul>li.selected>a')
})
##This updates the actual 'choice' value from 'Choice 1' to 'Choice1I am a tooltip title')
#Changing html to read:
html = 'title = "I am a tooltip title"',
#This replaces the choice (e.g. Choice 1) value so the drop down now has:
I am a tooltip title
Choice 2
Choice 3
想要为 pickerInput 选项的每个子项(选项卡索引)创建工具提示。应该只将“标题”属性添加到指定节点内的其他属性。
解决方案
知道了!自己回答,以防其他用户遇到此问题。
#server.R
observeEvent(input$actionbutton1,{
shinyjs::html(
html='<a tabindex="0" class=""...title="Your tooltip here"...></a>',
add=FALSE,
selector = '#form>div>form>div>div:nth-child(5)>div>div>div>ul>li:nth-child(4)' #This is the jquerySelector. Note that it will be different for each unique application. You will need to change the 'nth-child(#)' to the specific choice within 'SelectInput' to get a tooltip specific to that choice.)
})
推荐阅读
- python - render_to_string 似乎删除了变量的值
- next.js - 如果 NEXTJS 应用程序包含 [id].js 页面,如何在 Google 主机上部署它?
- javascript - 如何将具有单个值的 json 数组转换为键值对?
- tensorflow - CNN 模型准确率最高达到 99%,然后在 epochs 后下降到 50%
- python - 如何有效地获取 numpy 数组中相同值的数量?
- javascript - 更新“值”= 的属性更改 UI 中的值或输入时按下
- python - 为 Pandas 系列分配列名
- sql - SQL 如何将日期间隔拆分为一个或多个间隔?依赖于 ExcludeIntervals 表
- node.js - 我可以使用云功能同时为每个用户创建一个新文档吗?
- amazon-web-services - AWS Amplify (GraphQL) - 使用“graphqlOperation”与普通查询?