与单选button的html表复制粘贴到xls

我有一个HTML table元素,行不仅包含纯文本字符,还包括radio buttonslists等。

我想要的是当用户将表格内容复制粘贴到MS Excel(纯文本)时, radio buttons应该被replace为它们的值(例如:“checked”和“unchecked”),列表中的元素应该被选中的值replace

有没有办法在浏览器中实现这一点? (最好不使用Flash或Java小程序组件)

谢谢,克里斯

你可以使用JavaScript(这将更容易与像jQuery的框架)来修改已复制的代码。 一般的做法是将单选button设置为不可见,然后根据当前值在文本中添加文本。

有很多问题可以帮助实现细节: https : //stackoverflow.com/search?q=%5Bjavascript%5D+copied+text&submit=search

更新:原来你甚至不需要删除单选button,至less对于我的Excel版本。 这里是一个工作的例子(方式评论过来解释发生了什么):

 <!DOCTYPE html> <html> <head> <style type='text/css'> .radioCopyVal{ font-size: 0; } </style> </head> <body> <form> <table> <tr> <td><input type='radio' name='woots' id='oneWoot' checked/><span class='radioCopyVal'>Checked.</span></td> <td><label for='oneWoot'>Woot.</label></td> </tr> <tr> <td><input type='radio' name='woots' id='twoWoot' /><span class='radioCopyVal'>Not checked.</span></td> <td><label for='twoWoot'>Woot. Woot.</label></td> </tr> </table> </form> <script src="jquery-1.7.2.min.js"></script> <script type='text/javascript'> $("#oneWoot").attr("checked", true); //on page load, make sure oneWoot is the default selection $("input[name=woots]:radio").change(function(){ //anytime the radio buttons of name woots are changed... $(".radioCopyVal").remove(); //remove the old radioCopyVal spans (to be replaced with new ones) $("input[name=woots]:radio").each(function() { //for each radio button in name woots if ($(this).attr("checked")) { //if the button is checked, add a span saying 'Checked.' after it. css is used to hide the span $(this).after('<span class="radioCopyVal">Checked.</span>'); }else { $(this).after('<span class="radioCopyVal">Not checked.</span>'); } }) }); </script> </body> </html> 

不可能我害怕。 但你可以这样做:有一个链接,导致一个JavaScript和脚本将隐藏这些项目,并以纯文本显示它们的值,所以这个操作可以颠倒。

这可以很容易地使用JQuery完成:这显示了无线电值:

 $("input:radio").each(function() { if ($(this).attr("checked")) { $(this).after('<span class="value">checked</span>'); } else { $(this).after('<span class="value">unchecked</span>'); } }).css("display", "none"); 

我留下了一个span类,以便这些值可以很容易地用脚本隐藏。