javadocument
⑴ java document怎麼用啊
JSP或者HTML中的對象,可以獲取元素並且加以修改,如修改一個ID為xyz的輸入框的內容,就可以這樣:document.getElementById("xyz").value="修改的內容"。具體方法W3C上很多,直接網路 w3cschool,有你需要的資料
⑵ java腳本語言中document.write是什麼意思
親,document.write()是javascript中的,並不是java里的,java也並不是腳本語言.
document.write() 方法可以用在兩個方面:頁面載入過程中用實時腳本創建頁面內容,以及用延時腳本創建本窗口或新窗口的內容。該方法需要一個字元串參數,它是寫到窗口或框架 中的HTML內容。這些字元串參數可以是變數或值為字元串的表達式,寫入的內容常常包括HTML標記語言。
記住,在載入頁面後,瀏覽器輸出流自動關閉。在此之後,任何一個對當前頁面進行操作的document.write()方法將打開—個新的輸出流,它將清 除當前頁面內容(包括源文檔的任何變數或值)。因此,假如希望用腳本生成的HTML替換當前頁面,就必須把HTML內容連接起來賦給一個變數,使用一個 document.write()方法完成寫操作。不必清除文檔並打開一個新數據流,一個document.write()調用就可完成所有的操作。
關於document.write()方法還有一點要說明的是它的相關方法document.close()。腳本向窗口(不管是本窗口或其他窗口)寫完 內容後,必須關閉輸出流。在延時腳本的最後一個document.write()方法後面,必須確保含有document.close()方法,不這樣做 就不能顯示圖像和表單。並且,任何後面調用的document.write()方法只會把內容追加到頁面後,而不會清除現有內容來寫入新值。為了演示 document.write()方法,我們提供了同一個應用程序的兩個版本。一個向包含腳本的文檔中寫內容,另—個向—個單獨的窗口寫內容。請在文本編 輯器中鍵人每個文檔,以.html文件擴展名保存,並在瀏覽器中打開文檔。
示例1創建一個按鈕,它為文檔組合新的HTML內容,包括新文檔標題的HTML標記和<body>標記的顏色屬性。示例中有一個讀者所不熟悉 的操作符+=,它把其右側的字元串加到其左側的變數中,這個變數用來存放字元串,這個操作符能很方便地把幾個單獨的語句組合成—個長字元串。使用組合在 newContent變數中的內容,document.write()語句可以把所有新內容寫到文檔中,完全清除示例1中的內容。然後需要調用 document.close()語句關閉輸出流。當載入該文檔並單擊按鈕時,可以注意到瀏覽器標題欄中的文檔標題因此而改變。當回到原始文檔並再次單擊 該按鈕時,可以看到動態寫入的第二個頁面的載入速度甚至比重載原始文檔還要快。
示例1 在當前窗口使用document.write()。
<html>
<head>
<title>Writing to Same Doc</title>
<script language="JavaScript">
function reWrite(){
// assemble content for new window
var newContent = "<html><head><title>A New Doc</title></head>"
newContent += "<body bgcolor='aqua'><h1>This document is brand new.</h1>"
newContent += "Click the Back button to see original document."
newContent += "</body></html>"
// write HTML to new window document
document.write(newContent)
document.close() // close layout stream
}
</script>
</head>
<body>
<form>
<input type="button" value="Replace Content" onClick="reWrite()">
</form>
</body>
</html>
示例2中,情況有點復雜,因為腳本創建了一個子窗口,整個腳本生成的文檔都將寫入該窗口中。為了使新窗口的引用在兩個函數中保持激活狀態,我們將 newWindow變數聲明為全局變數。頁面載入時,onLoad事件處理調用makeNewWindow()函數,該函數生成一個空的子窗口。另外,我 們在window.open()方法的第三個參數中加入一個屬性,使子窗口的狀態欄可見。
頁面上的按鈕調用subWrite()方法,它執行的第一個任務是檢查子窗口的closed屬性。假如關閉了引用窗口,該屬性(只在較新的瀏覽器版本中存 在)返回true。如果是這種情況(假如用戶手動關閉窗口),該函數再次調用makeNewWindow()函數來重新打開那個窗口。
窗口打開後,新的內容作為字元串變數組合在一起。與示例1一樣,一次性寫入內容(雖然對單獨的窗口沒有必要),接下來調用close()方法。但是注意一個重要的區別:write() 和 close()方法都明顯地指定了子窗口。
示例2 在另一個窗口中使用document.write()
<html>
<head>
<title>Writing to Subwindow</title>
<script language="JavaScript">
var newWindow
function makeNewWindow(){
newWindow = window.open("","","status,height=200,width=300")
}
function subWrite(){
// make new window if someone has closed it
if(newWindow.closed){
makeNewWindow()
}
// bring subwindow to front
newWindow.focus()
// assemble content for new window
var newContent = "<html><head><title>A New Doc</title></head>"
newContent += "<body bgcolor='coral'><h1>This document is brand new.</h1>"
newContent += "</body></html>"
// write HTML to new window document
newWindow.document.write(newContent)
newWindow.document.close() // close layout stream
}
</script>
</head>
<body onLoad="makeNewWindow()">
<form>
<input type="button" value="Write to Subwindow" onClick="subWrite()">
</form>
</body>
</html>
⑶ 用java做文本編輯器如何打開document文件
package com.zcsoft.test;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.filechooser.FileFilter;
public class Note extends JFrame
{
public Note()
{
super("文本編輯器");
setSize(500, 300);
final JTextArea txtArea = new JTextArea(8, 50);
JButton chooseFileButton = new JButton("選擇文件");
chooseFileButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.addChoosableFileFilter(new FileFilter() {
@Override
public String getDescription() {
return "請選擇(.txt)";
}
@Override
public boolean accept(File f) {
boolean accept = f.isDirectory();
if( ! accept)
{
String s = f.getPath(), suffix = null;
int i = s.lastIndexOf('.');
if(i > 0 && i < s.length() - 1)
suffix = s.substring(i+1).toLowerCase();
if(suffix != null)
accept = f.isDirectory() || suffix.equals("txt");
}
return accept;
}
});
fileChooser.showOpenDialog(Note.this);
File file = fileChooser.getSelectedFile();
try {
FileInputStream in = new FileInputStream(file);
byte[] context = new byte[1024];
int length = -1;
StringBuffer sb = new StringBuffer();
while ((length = in.read(context)) != -1) {
sb.append(new String(context));
}
txtArea.setText(sb.toString());
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
setLayout(new BorderLayout());
add(txtArea, BorderLayout.CENTER);
add(chooseFileButton, BorderLayout.SOUTH);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Note();
}
}
⑷ document獲取在Java中獲取text沒有的值用什麼判斷
new。
:參數是指函數括弧里的東西,返回值是函數執行之後的結果。舉個例子哈:intA這是無參函數、intAintB這是有參函數參數為B。voidA這是無返回值的函數,只要是在函數定義的時候,函數名前面沒有void,均為有返回值的函數。
還是String類型,不知你們是否使用Hibernate框架,使用的話可以給String類型設置最大長度。12@Columnlength=,此欄位,對應成了LongText類型可能,不確定。
⑸ java中運用javascripte的時候,document是指什麼
document 是指整個html頁面
取所有東西的時候都得用document.
用這個來指定
⑹ java類中一個document對象doc,要刪除其head節點下的內容返回一個document怎麼實現
document.getElementsByTagName("head")[0].parentNode.removeChild(document.getElementsByTagName("head")[0]);
測試樣例
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>test1</title>
</head>
<body>
<scripttype="text/javascript">
document.getElementsByTagName("head")[0].parentNode.removeChild(document.getElementsByTagName("head")[0]);
</script>
<divname="div"id="12263"flag="0">
</body>
</html>