js高级编程笔记2

1.document.open -- 打开已经载入的文档
var win = window.open("about:blank","dreamdu");
win.document.open();
win.document.write("welcome to dreamdu!");
win.document.close();
2.document.getSelection()获取页面上选中的文字:
<script type="text/javascript">
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
function showSelection(){
if(window.getSelection) {
alert(window.getSelection());
}
else if (document.getSelection) {
alert(document.getSelection());

}
else if (document.selection) {
alert(document.selection.createRange().text);
}
}
if (isNav) {
document.captureEvents(Event.MOUSEUP);
}
document.onmouseup = showSelection;
</script>
</head>
<body>aaaaaaaaaaaaaaaa1111111111111
<textarea name="selectedText" rows = 3 cols=40 wrap="virtusl">
</textarea>
</body>

ff中:

function getTextFieldSelection(e) {
if (e.selectionStart != undefined && e.selectionEnd != undefined) {
var start = e.selectionStart;
var end = e.selectionEnd;
return e.value.substring(start, end);
}
else return "";
}

3.文本对象的 select()选定文本对象的文本

4.一般的对象在表单域中提交信息的长度不能超过256个字节,超过过时用文本区域对象type="textarea"




原文地址:https://www.cnblogs.com/ylemzhang/p/1911337.html