在javascript中使用pasteHTML的替代方法? [英] alternative method for pasteHTML in javascript?

查看:69
本文介绍了在javascript中使用pasteHTML的替代方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于javascript中的pasteHTML()函数有没有替代方法?在选择html表并在range.pasteHTML()的帮助下更换时,它显示了缺省错误,当选择htmltext时它完美地工作..这个问题是否有解决方案?

解决方案

据我所知,这些是特定于Internet Explorer的东西。其次,通过文本操作来改变DOM是一种相当荒废的方法。我建议你使用DOM的面向对象方法。实际上你最好使用一个javascript库,如 JQuery [ ^ ]干净利落,干净利落。你可以从这里开始:

http://www.tutorialspoint.com/jquery/jquery -dom.htm [ ^ ]

http://www.jquery-tutorial.net/dom-manipulation/introduction / [ ^ ]


参考 - jQuery - 是否可能复制并粘贴HTML? [ZoltánZörgő的建议, jQuery 中的新窗口> ^ ]。


 <   html  >  
< < span class =code-leadattribute> head >
< title > Untitled-3 < / title >
< meta http-equiv = 内容类型 content = text / html; charset = utf-8 >
< / head >
< body bgcolor = #FFFFFF leftmargin = 0 topmargin = 0 marginwidth = 0 marginheight = 0 >
<! - 保存Web切片(Untitled-3.psd) < span class =code-comment> - >
< id = Table_01 width = 595 height = 864 border = 0 cellpadding = 0 cellspacing = 0 >
< tr >
< td colspan = 3 > < a href = http://www.kotaapps.com/ > < img src = http://www.imageurlhost.com/images/jq9ac0hxu009vnkml1ah.gif width = 595 height = 781 alt = > < / a > < / td >
< / tr >
< tr >
< td rowspan = 2 > < a href = http://www.kotaapps.com/ > ; < img src = http://www.imageurlhost.com/ images / zi9rov1w0f6yq8ptifsk.gif width = 187 height = 83 alt = > < / a > < / td >
< td > < a href = https:/ /itunes.apple.com/us/app/nozoom-fix-your-wallpaper/id793024257?mt=8\"> < img src = http://www.imageurlhost.com/images/2tbxp4t5hqh6xn9mrfm9.gif width = 214 height = 52 alt = > < / a > < / td >
< td rowspan = 2 > < a < span class =code-attribute> href = http://www.kotaapps.com/ > < img src = http://www.imageurlhost.com/images/bzo73woan8pd7xa7hbpt.gif < span class =code-attribute> width = 194 height = 83 alt = > < < span class =code-leadattribute> / a > < / td >
& / tr >
< tr >
< td > < a href = http://www.kotaapps.com/ > < img src = http://www.imageurlhost .com / images / 8hqcuorydesd6ju772ow.gif width = 214 height = 31 alt = > < / a > < / td >
< / tr >
< /表 >
<! - 结束网页保存 - >
< / body >
< / html >


Is There any Alternative Method For pasteHTML() function in javascript ?? while selecting html table and replacing with the help of range.pasteHTML() it shows UNSPECIFIED ERROR , when selecting htmltext it works perfectly ..is there any solution for this problem??

解决方案

As I know, these are Internet Explorer specific things. Second, it is quite a deprecated approach to alter the DOM by text manipulation. I suggest you use the object oriented approach of DOM. Actually you better use a javascript library such as JQuery[^] to do it neat, clean and easy. You could start here:
http://www.tutorialspoint.com/jquery/jquery-dom.htm[^]
http://www.jquery-tutorial.net/dom-manipulation/introduction/[^]


Refer - jQuery - Is it possible copy and paste HTML?[^] to it in jQuery, as suggested by Zoltán Zörgő.


<html>
<head>
<title>Untitled-3</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (Untitled-3.psd) -->
<table id="Table_01" width="595" height="864" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td colspan="3"><a href="http://www.kotaapps.com/"><img src="http://www.imageurlhost.com/images/jq9ac0hxu009vnkml1ah.gif" width="595" height="781" alt=""></a></td>
    </tr>
    <tr>
        <td rowspan="2"><a href="http://www.kotaapps.com/"><img src="http://www.imageurlhost.com/images/zi9rov1w0f6yq8ptifsk.gif" width="187" height="83" alt=""></a></td>
        <td><a href="https://itunes.apple.com/us/app/nozoom-fix-your-wallpaper/id793024257?mt=8"><img src="http://www.imageurlhost.com/images/2tbxp4t5hqh6xn9mrfm9.gif" width="214" height="52" alt=""></a></td>
        <td rowspan="2"><a href="http://www.kotaapps.com/"><img src="http://www.imageurlhost.com/images/bzo73woan8pd7xa7hbpt.gif" width="194" height="83" alt=""></a></td>
    </tr>
    <tr>
        <td><a href="http://www.kotaapps.com/"><img src="http://www.imageurlhost.com/images/8hqcuorydesd6ju772ow.gif" width="214" height="31" alt=""></a></td>
    </tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>


这篇关于在javascript中使用pasteHTML的替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆