我使用Xoxco的插件进行标记输入,如下所示:
http://xoxco.com/projects/code/tagsinput/
在我的修改中,我使用了JQuery的focus()函数
<input id="tags_1" class="tag-holder" type="text" class="tags" /></p>
<div id="std" style="display:none;">
<span id='pdf' onmouseover="" style="cursor: pointer;">PDF</span>
<p id="reset" onmouseover="" style="cursor: pointer;">Reset Tags</p>
</div>我的JQuery是
$('#tags_1').focus(function(){
$('#std').css('display','block');
});然而,当我修改插件时,这似乎不起作用。它不需要使用插件就可以单独工作。我在这里漏掉什么了吗?
发布于 2014-01-10 10:43:50
因为问题是它在元素id中添加了一个_tag,并且这个id不再可用,所以您必须针对这个id #tag_1_tag。
所以你的代码应该是这样的:
命令事项
$('#tags_1').tagsInput({width: 'auto'}); //<----tagInput applied
$('#tags_1_tag').focus(function(){ //<-----this id has to be the target now
$('#std').css('display','block');
});演示Fiddle
甚至您也可以使用属性选择器:
$('[id^="tags_1"]').focus(function(){ //<-----this id has to be the target now
$('#std').css('display','block');
});带有属性选择器的演示
https://stackoverflow.com/questions/21041800
复制相似问题