【发布时间】:2019-07-22 13:09:18
【问题描述】:
我需要在鼠标点击时选择 div 内容(只有 TEXT 没有最后一个空格)
<div>
<div id="block1">
Please send the following code
</div>
<div id="block2" style="font-size:40px; background-color:#fffb95;" onclick="selectText('block2')" >
@Html.DisplayFor(c => c.GeneratedCode, new { id = "genCode" })
</div>
<div id="block3">
to your vendor to generate an access code which is required for your authentication.
</div>
</div>
脚本
function selectText(containerid) {
if (document.selection) { // IE
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().removeAllRanges();
window.getSelection().addRange(range );
}
}
风格
#block1, #block2, #block3 {
display: inline;
}
.input-lg {
height: 43px;
}
【问题讨论】:
标签: javascript jquery css asp.net-mvc