如何将HTML中的文本值复制到剪贴板?

时间:2014-08-28 13:44:47

标签: html clipboard copy-paste

我试图通过重新组织网页的css或复制到剪贴板快捷方式从网页中提取多个值,以便将值直接发送到剪贴板。

<fieldset id="property_info">
    <legend>Property Information</legend>
        <table id="prop_table">
            <tbody>
                <tr>
                    <td><label for="street_num">Street Num</label></td>
                    <td><input name="form[street_num]" id="street_num" class="required" value="1223" type="text"></td>
                    <td><input name="form[address1]" id="address1" class="required" value="CABRILLO PARK" type="text"></td>

例如,如果不必突出显示页面上的值,我可以通过某种方式发送&#34; 1223&#34;还有价值&#34; CABRILLO PARK&#34;同时使用autohotkey或其他任何东西到我的剪贴板?要么重新排列css?

2 个答案:

答案 0 :(得分:0)

剪贴板是棘手的事情。您不允许在javascript中对它们进行太多操作,并且它在浏览器中有所不同。参见:

How do I copy to the clipboard in JavaScript?

答案 1 :(得分:0)

对于Autohotkey,(分号表示已注释):

!2::   ; !2 means alt 2, change convenient key combination
file_containing_example_html_you_posted:="http://www.autohotkey.com/docs/misc/Clipboard.htm" 
valueofthis:="value="""  ; double quotes means 1 quote, ending quote *is* required
clipboard_me_some_htmls(file_containing_example_html_you_posted,valueofthis,1)
return
clipboard_me_some_htmls(url,stringtofind,whichone)
{
    file:="here.html" ; website cached here to be read from, can be changed to file path, defaults to script directory
    ;UrlDownloadToFile, %url% , %file%
    fileread, htmls , %file%
    aquote:="""" ; two quotes means one quote
    StringGetPos, valuelocation,  htmls, %stringtofind%
    StringGetPos, quotelocation,  htmls, %aquote%,L%whichone%,%valuelocation% ; find immediate next quote
    StringMid, valuesvalue, htmls,% valuelocation+StrLen(stringtofind)+1, % quotelocation-valuelocation-2 ;get string between stringtofind and the next quote
    Clipboard:=valuesvalue ; press ctrl v afterwards and enjoy your saved time
}

使用URL作为您要扫描的网站调用该函数,保持stringtofind与现在相同,whichone在第一次出现时为1,第二次出现时为1223 。在示例中,您将{1}放入剪贴板,将CABRILLO PARK放入剪贴板中。