Javascript 如何修复';setAttributeNode(att)和#x27;是否要添加属性或修改现有属性?
我正在使用Javascript 如何修复';setAttributeNode(att)和#x27;是否要添加属性或修改现有属性?,javascript,r,dom,shiny,Javascript,R,Dom,Shiny,我正在使用shinyJS包以及shinny标记和传统HTML向现有元素添加属性“title”。我可以在控制台(inspector[Google CHROME])内完成这项工作,但当我试图通过ui.R或server.R应用相同的输入时,要么没有任何变化,要么实际文本值发生变化(工具提示) 如上所述,我尝试了以下方法: shinyJS:html() 闪亮:标记$HTML;标记$body(标记$script()) HTML:在HTML文件(mychange.HTML)中添加更改,并从www 要修改的输
shinyJS
包以及shinny
标记和传统HTML向现有元素添加属性“title”。我可以在控制台(inspector[Google CHROME])内完成这项工作,但当我试图通过ui.R或server.R应用相同的输入时,要么没有任何变化,要么实际文本值发生变化(工具提示)
如上所述,我尝试了以下方法:
shinyJS
:html()
闪亮
:标记$HTML;标记$body(标记$script())
HTML:在HTML文件(mychange.HTML)中添加更改,并从www
要修改的输入(添加工具提示)
以下是正确的函数(当它在web inspector下的控制台中运行时会更新):
然而,在R
shinyJS
要为pickerInput选项的每个子项(选项卡索引)创建工具提示。只需将“title”属性添加到指定节点内的其他属性即可。明白了!我自己回答,以防其他用户遇到此问题
#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.)
})
#server.R
observeEvent(输入$actionbutton1{
shinyjs::html(
html=“”,
add=FALSE,
选择器='#form>div>form>div>div:nth child(5)>div>div>ul>li:nth child(4)'#这是jquerySelector。请注意,对于每个唯一的应用程序,它都是不同的。您需要将'nth child(#)更改为'SelectInput'中的特定选项,以获取特定于该选项的工具提示。)
})
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);
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
#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.)
})