首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript选择返回错误的偏移量

Javascript选择返回错误的偏移量
EN

Stack Overflow用户
提问于 2014-11-14 15:26:09
回答 1查看 2K关注 0票数 1

问题: Selection#anchorOffsetSelection#baseOffset & Selection#focusOffset不时返回错误的值。

预期行为:双击代码片段(feature)中的第二个单词。您应该看到警报'anchor: feature'

问题:如何得到正确的值?

JSFiddle演示: http://jsfiddle.net/v2mmabzm/5/

演示:

代码语言:javascript
复制
$(document).ready(function()
{
    var p = $('p.text-container')
    p.css({ cursor: 'pointer' });
    p.dblclick(function(e) {
        var html = $(e.target).html();
        var range = window.getSelection() || document.getSelection() || document.selection.createRange(); 
        var selectedWord = $.trim(range.toString());            
        debugger;
        var anchorOffset = range.anchorOffset;
        var baseOffset = range.baseOffset;
        var focusOffset = range.focusOffset;        
        alert('anchor: ' + html.substring(anchorOffset, anchorOffset + selectedWord.length));
        alert('base: '   + html.substring(baseOffset,   baseOffset   + selectedWord.length));
        alert('focus: '  + html.substring(focusOffset,  focusOffset  + selectedWord.length));
    });    
});
代码语言:javascript
复制
span.touched {
    font-weight: bold;
}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<p class="text-container">
The future of manned space exploration and development of space depends critically on the creation of a dramatically more proficient propulsion architecture for in-space transportation. A very persuasive reason for investigating the applicability of nuclear power in rockets is the vast energy density gain of nuclear fuel when compared to chemical combustion energy. Current nuclear fusion efforts have focused on the generation of electric grid power and are wholly inappropriate for space transportation as the application of a reactor based fusion-electric system creates a colossal mass and heat rejection problem for space application. The Fusion Driven rocket (FDR) represents a revolutionary approach to fusion propulsion where the power source releases its energy directly into the propellant, not requiring conversion to electricity. It employs a solid lithium propellant that requires no significant tankage mass. The propellant is rapidly heated and accelerated to high exhaust velocity (&gt; 30 km/s), while having no significant physical interaction with the spacecraft thereby avoiding damage to the rocket and limiting both the thermal heat load and radiator mass. In addition, it is believed that the FDR can be realized with little extrapolation from currently existing technology, at high specific power (~ 1 kW/kg), at a reasonable mass scale (&lt;100 mt), and therefore cost. If realized, it would not only enable manned interplanetary space travel, it would allow it to become common place. The key to achieving all this stems from research at MSNW on the magnetically driven implosion of metal foils onto a magnetized plasma target to obtain fusion conditions. A logical extension of this work leads to a method that utilizes these metal shells (or liners) to not only achieve fusion conditions, but to serve as the propellant as well. Several low-mass, magnetically-driven metal liners are inductively driven to converge radially and axially and form a thick blanket surrounding the target plasmoid and compress the plasmoid to fusion conditions. Virtually all of the radiant, neutron and particle energy from the plasma is absorbed by the encapsulating, metal blanket thereby isolating the spacecraft from the fusion process and eliminating the need for large radiator mass. This energy, in addition to the intense Ohmic heating at peak magnetic field compression, is adequate to vaporize and ionize the metal blanket. The expansion of this hot, ionized metal propellant through a magnetically insulated nozzle produces high thrust at the optimal Isp. The energy from the fusion process, is thus utilized at very high efficiency. Expanding on the results from the phase I effort, phase II will focus on achieving three key criteria for the Fusion Driven Rocket to move forward for technological development:
    </p>
</body>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-14 15:43:38

只要改变

代码语言:javascript
复制
var html = p.text();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26933332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档