选择< p>方法 [英] Select <p> method
问题描述
有没有办法选择< p>使用jscript?
Is there a way to select <p> using jscript ?
我有这段代码可以选择< p> div作为对话框打开但是< p>未预先选择(待复制)
I have this code to enable selecting <p> text when the div opens as dialog but <p> is not preselected (to be copied)
< div id =" dialog" title ="基本对话框" style =" display:none">
< p id =" para">复制此密钥< / p>
< p id =" key"> 4567887654345678< / p>
< / div>
<div id="dialog" title="Basic dialog" style="display: none">
<p id="para">Copy this key</p>
<p id="key">4567887654345678</p>
</div>
< button>打开对话框< / button>
<button>Open dialog</button>
$(function(){
$(" button")。click(function(){
$("#dialog")。。dialog();
$( "#dialog""。show(" slow");
; $("#key")。select();
});
});
$(function() {
$( "button" ).click(function() {
$("#dialog" ).dialog();
$( "#dialog" ).show( "slow" );
$("#key").select();
});
});
推荐答案
嗨。选择 仅适用于文字输入和textarea元素 (请参阅文档
此处)。因此,只读输入可能是最简单的方法。
Hi. Select only works on text input and textarea elements (see the documentation here). So maybe a readonly input would be the easiest way to go.
<input type="text" id="key" value="4567887654345678" readonly>
这篇关于选择< p>方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!