本文介绍了如何测试特定于浏览器的方法,如document.selection.createRange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这是在我使用它之前测试方法的正确方法吗? createRange()我相信是一种IE唯一的方法。 function wrapSelectionInTag(选择,标记){ if(document.selection.createRange){ var range = document.selection.createRange(); if (range.parentElement()== element)range.text =''<''+ tag + ''>''+ range.text +''< \ /' '+ tag +''>''; } } 解决方案 这是一种专有方法,但这并不一定意味着只有IE 支持它。不过,我不能说出其他人的名字。 [snip] Mike *请不要在Usenet上使用标签进行缩进。在发布之前将它们转换为空格 。 - Michael Winter 替换 。无效"与.uk通过电子邮件回复。 这是一种专有方法,但这并不一定只意味着IE 支持它。但是,我不能说出任何其他人的名字。 似乎已经在DOM Level 2中采用了 < URL:http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/ranges.html#Level2-DocumentRange-method-createRange> 我已经在Mozilla和Safari中测试了它(它的工作原理......)。 Rob。 [snip] 似乎已经在DOM Level 2中采用了 [URL到DOM 2 Traveral和范围规格] [snip] 据我所知,它们是两回事。 由Microsoft引入的document.selection.createRange方法, 反映了用户选择的文本。 文档由W3C引入的.createRange方法选择文档树的 部分,允许你将它作为一个块操作 (基本上)。 Mike - Michael Winter 替换.invalid与.uk通过电子邮件回复。 Is this the correct way to test for a method before I use it?createRange() is, I believe, an IE only method.function wrapSelectionInTag(selection, tag) {if (document.selection.createRange) {var range = document.selection.createRange();if (range.parentElement() == element) range.text = ''<'' + tag +''>'' + range.text + ''<\/'' + tag + ''>'';}} 解决方案 It is a proprietary method, but that doesn''t necessarily mean only IEsupports it. I can''t name any others that do, though. [snip] Mike*Please* don''t use tabs for indentation on Usenet. Convert them to spacesbefore posting. --Michael WinterReplace ".invalid" with ".uk" to reply by e-mail. It is a proprietary method, but that doesn''t necessarily mean only IE supports it. I can''t name any others that do, though. Seems it''s been adopted in DOM Level 2 <URL:http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/ranges.html#Level2-DocumentRange-method-createRange> I''ve tested it in Mozilla and Safari (it works...).Rob. [snip] Seems it''s been adopted in DOM Level 2 [URL to DOM 2 Traveral and Range Specification] [snip] As I understand it, they are two different things. The document.selection.createRange method, as introduced by Microsoft,reflects text selected by the user. The document.createRange method, as introduced by the W3C, selects aportion of the document tree, allowing you to manipulate it as a block(essentially). Mike --Michael WinterReplace ".invalid" with ".uk" to reply by e-mail. 这篇关于如何测试特定于浏览器的方法,如document.selection.createRange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-21 00:30