在jQuery中单击时选择的整个文本
<tr>
<td class="wt" type="text" contenteditable="true" align="right">0.00</td>
</tr>
答案 0 :(得分:0)
希望这会有所帮助:
$('#selectAll').on('focus', function() {
var cell = this;
var range, selection;
if (document.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(cell);
range.select();
} else if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(cell);
selection.removeAllRanges();
selection.addRange(range);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr>
<td><div id="selectAll" contenteditable="true">0.00</div></td>
</tr>