我有以下非常简单的html页面:
<html>
<head>
<script type="text/javascript">
function alertSelection()
{
var selection = window.getSelection();
var txt = selection.toString();
alert(txt);
}
</script>
</head>
<body>
This is <span style="background-color:black;color:white">the</span> text.
<div style="background-color:green;width:30px;height:30px;margin:30px"
onmouseover="alertSelection()">
</body>
</html>
当我选择整个第一行并将鼠标放在正方形上时,我得到一个警告"This is the text.“。
我如何解决这个问题,使span标记或任何其他选定的HTML不会从警报消息中删除?
编辑:我正在寻找如何从window.getSelection()
获取完整的。警告对话框正是我尝试验证代码的方式。我只关心在Safari中的工作。
https://stackoverflow.com/questions/4652734
复制相似问题