问题: Selection#anchorOffset
,Selection#baseOffset
& Selection#focusOffset
不时会返回错误的值。
预期行为:双击代码段中的第二个单词(feature
)。您应该看到提示'anchor: feature'
。
问题: 如何获得正确的值?
JSFiddle演示: http://jsfiddle.net/v2mmabzm/5/
演示:
$(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));
});
});

span.touched {
font-weight: bold;
}

<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 (> 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 (<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>
&#13;
答案 0 :(得分:2)
只需更改
var html = p.text();