将html表单写入和读取到文本文件javascript

时间:2015-04-23 16:50:32

标签: javascript vb.net

我已经在vb中写入了对文本文件的读写html表单。我是javascript的新手,谁能指导我如何将这些代码转换为javascript?以下javascript是我试图隐蔽但代码不起作用。请指正。谢谢。

vb.net代码

    Dim filename As String = "C:\Users\Kit\test.txt"
    If System.IO.File.Exists(filename) = True Then
        Dim objwriter As New System.IO.StreamWriter(filename)
        objwriter.WriteLine(TextBox1.Text)
        objwriter.WriteLine(TextBox2.Text)
        objwriter.WriteLine(TextBox3.Text)
        objwriter.Close()
        MsgBox("Text written to file")
    Else
        File.Create("C:\Users\Kit\test.txt").Dispose()
        Dim objwriter As New System.IO.StreamWriter(filename)
        objwriter.WriteLine(TextBox1.Text)
        objwriter.WriteLine(TextBox2.Text)
        objwriter.WriteLine(TextBox3.Text)
        objwriter.Close()
        MsgBox("Text written to file")
    End If


    Dim filename As String = "C:\Users\Kit\test.txt"
    If System.IO.File.Exists(filename) = True Then
        Dim objreader As New System.IO.StreamReader(filename)
        TextBox1.Text = objreader.ReadLine
        TextBox2.Text = objreader.ReadLine
        TextBox3.Text = objreader.ReadLine
        objreader.Close()
        MsgBox("Text written to file")
    Else
        MsgBox("File Does Not Exist")
    End If

Javascript

 function writefile()
 {  If (System.IO.File.Exists(filename)) = True Then
 {
    var objwritter = new StreamWritter("C:\Users\Kit\test.txt")
    objwriter.WriteLine(TextBox1.Text);
    objwriter.WriteLine(TextBox2.Text);
    objwriter.WriteLine(TextBox3.Text);
    objwritter.Close();
    MsgBox("Text written to file")
}       
Else
{
    File.Create("C:\Users\Kit\test.txt").Dispose()
    Dim objwriter As New System.IO.StreamWriter(filename)
    objwriter.WriteLine(TextBox1.Text);
    objwriter.WriteLine(TextBox2.Text);
    objwriter.WriteLine(TextBox3.Text);
    objwriter.Close();
    MsgBox("Text written to file")
}
End If
}

function readfile()
{
objread = new StreamReader("C:\Users\Kit\test.txt");
objread.WriteLine(TextBox1.Text)
objread.WriteLine(TextBox2.Text)
objread.WriteLine(TextBox3.Text)
objread.Close() 
}

0 个答案:

没有答案