我想使用 javascript 获取选定的文本位置。例如,
我有一个简单的 textarea。
#input-text {
resize: none;
width: 50%;
height: 50px;
margin: 1rem auto;
}Run Code Online (Sandbox Code Playgroud)
<textarea id="input-text">I am a student and I want to become a good person</textarea>Run Code Online (Sandbox Code Playgroud)
在我的 textarea 中,我有一些文本,例如:
"I am a student and I want to become a good person"
Run Code Online (Sandbox Code Playgroud)
从这个字符串中,如果我从 textarea 中选择“成为一个好人”,
那么我如何在 javascript 中获取选定的文本/字符串位置?
这里选择的字符串字符从 29 开始,到 49 结束。所以开始位置是 29 & 结束位置是 49
我们知道这let是一个保留关键字,它在 JavaScript 中定义了一个变量。
var let = 2;
console.log(let); // return 2
Run Code Online (Sandbox Code Playgroud)
那么为什么这不是错误呢?
我正在通过Next.js.
Next.js提供SSR和dynamic routing。
express吗?express没有提供的有用Next.js?我认为next build&next start显示页面和我预期的一样。
document.execCommand() 已被废弃[DOC]。所以,2020年制作所见即所得编辑器并不是那么容易。 看了很多文章和答案后才发现,大部分答案(开发者)更喜欢使用:
但是如何?他们没有举任何例子。我想让“伏地魔”这个词在点击B按钮后加粗。我只需要了解工作流程。
<div class="block-editor">
<!-- editor control -->
<div class="block-editor-control">
<ul>
<li data-action="bold"> B </li>
</ul>
</div>
<!-- editor content's -->
<div class="block-editor-content">
<div class="block-editor-block" contenteditable="true" role="group">
Voldemort is back
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 当我点击按钮时我有点击事件,当我按下回车键时有一个按键事件。但问题是在单击按钮后,如果我不单击文档并按 Enter 键,该process()函数会执行两次。我也尝试使用捕获类型修复它,但没有找到解决方案。
它发生在按钮焦点上吗?
我该如何解决这个双重执行问题?
let
button = document.querySelector('button'),
input = document.querySelector('input');
button.addEventListener('click', process);
document.addEventListener('keypress', function(e){
if (e.keyCode == 13)
process();
});
function process(){
console.log(
input.value
);
}Run Code Online (Sandbox Code Playgroud)
<input type="text" value="sometext"/>
<button> Action </button>Run Code Online (Sandbox Code Playgroud)
在我的动画中,我喜欢使用变换。这也可以用财产来实现left/right。但我喜欢使用变换。我需要将freeze-loading-bar100% 向右移动,它应该是一个无限循环。
我怎样才能将其
loading-bar向右移动100%/完全?
*,
*::before,
*::after {
box-sizing: border-box;
}
.app-view {
height: 200px;
max-width: 300px;
margin: 1rem auto;
background-color: #fff;
box-shadow: -2px 2px 4px 0 #e0e0e0ad, 1px -1px 9px 0 #dddddd2e;
padding: 2rem;
display: flex;
align-items: center;
justify-content: center;
}
.freeze-loading {
position: relative;
width: 100%;
height: 5px;
box-shadow: inset 1px 0px 4px 0 #ddd;
/** disual purpose **/
/** overflow: hidden; **/
}
.freeze-loading-bar {
position: absolute;
left: 0;
width: 80px;
height: …Run Code Online (Sandbox Code Playgroud)