简体   繁体   English

如何在glyphicon点击上突出显示contentEditable span

[英]How to highlight a contentEditable span on glyphicon click

I have 2 spans 我有2个跨度

<span contentEditable=true class="editspan"></span>
<span class="pencilspan glyphicon glyphicon-pencil pull-right"></span>

and a js function 和一个js功能

$(document).on('click', '.pencilspan', function () {
    console.log("clicked pencil");
});

What I want is when I click on pencilspan the contentEditable area of editspan should get highlighted(input box should be visible). 我想要的是当我点击pencilpan时,editspan的contentEditable区域应该突出显示(输入框应该是可见的)。 How can I achieve this? 我怎样才能做到这一点?

You should try focus() method : 你应该尝试focus()方法:

$(document).on('click', '.pencilspan', function () {
    $(this).siblings('.editspan').focus();
});

For empty span issue you can follow this link 对于空跨度问题,您可以点击此链接

Please try this might help you if you are looking for toggle: 如果您正在寻找切换,请尝试这可能会对您有所帮助:

<!DOCTYPE html>
<html>
<head>
<style>
.editInput{
display:none;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

</head>
<body>
<span contentEditable=true class="editspan">
<input type = 'text' value ='' class='editInput' />
</span>
<span class="pencilspan glyphicon glyphicon-pencil pull-right">button</span>
<script>
$(document).ready(function(){
  $(document).on('click', '.pencilspan', function () {
   // var editInput = "<input type = 'text' value ='' />";
    $('.editspan .editInput').toggle();

});
});
</script>
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在单击glyphicon时强制单击span元素 - How to force click a span element on click of glyphicon 双击 IE 11 上的 contentEditable 突出显示问题 - Double click contentEditable highlight issue on IE 11 点击 div[contenteditable] 如果最后一个元素是 span[contenteditable=&quot;false&quot;] - click on div[contenteditable] if last element is span[contenteditable="false"] 我有contenteditable div,并且在它内部是一个不可编辑的span,如何能够通过长按在整个span文本上标记div的文本 - I have contenteditable div , and inside it is a noneditable span, how to be able to mark the div's text with a long click thrugh the span text 如何防止使用 contenteditable 删除跨度内? - How to prevent remove inside span using contenteditable? 如何在contentedable span中设置插入位置然后发送Keys? - How to set caret position in contenteditable span and then sendKeys? 我们如何在正则表达式中替换 span contenteditable? - how can we replace span contenteditable in regex? 如何将光标移动到 ContentEditable Span 的开头/结尾 - How to move cursor to beginning/end of ContentEditable Span 如何在内容可编辑范围内设置光标位置 - How to set cursor position in contenteditable span 如何在contenteditable div中的跨度中设置光标位置 - How to set cursor position in span in contenteditable div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM