亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 ac# 字符串保存為 html 文件

將 ac# 字符串保存為 html 文件

當年話下 2023-09-04 15:39:36
我有一個 c# 腳本,它在某個時候創建一個字符串變量,如何將其另存為 HTML 文件在腳本的同一目錄中? string saveHtml = "<html>" +    "<head>" +    "  <title>Select Image</title>" +    "  <script type=\"text/javascript\">" +    "  function displayImage(elem) {" +    "    var image = document.getElementById(\"canvas\");" +    "    image.src = elem.value;        " +    "  }" +    "  </script>" +    "</head>" +    "<body>" +    "  <form name=\"controls\">" +    "    <img id=\"canvas\" src=\"pictures/fire1.jpg\" />" +    "    <select name=\"imageList\" onchange=\"displayImage(this);\">" +    "      <option value=\"pictures/001JRPchargeable.png\">Fire 1</option>" +    "      <option value=\"pictures/001JRPNonchargeable.png\">Fire 2</option>" +"</select>" +"  </form>" +"</body>" +"</html>";
查看完整描述

2 回答

?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

class Program

{

? ? static void Main(string[] args)

? ? {

? ? ? ? string saveHtml = "<html>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "<head>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? <title>Select Image</title>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? <script type=\"text/javascript\">" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? function displayImage(elem) {" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? ? var image = document.getElementById(\"canvas\");" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? ? image.src = elem.value;? ? ? ? " +

? ? ? ? ? ? ? ? ? ? ? ? ? "? }" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? </script>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "</head>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "<body>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? <form name=\"controls\">" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? ? <img id=\"canvas\" src=\"pictures/fire1.jpg\" />" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? ? <select name=\"imageList\" onchange=\"displayImage(this);\">" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? ? ? <option value=\"pictures/001JRPchargeable.png\">Fire 1</option>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? ? ? <option value=\"pictures/001JRPNonchargeable.png\">Fire 2</option>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "</select>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "? </form>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "</body>" +

? ? ? ? ? ? ? ? ? ? ? ? ? "</html>";


? ? ? ? File.WriteAllText(@"C:\temp\theFile.html", saveHtml);

? ? }

}


查看完整回答
反對 回復 2023-09-04
?
慕后森

TA貢獻1802條經驗 獲得超5個贊

您可以使用此代碼:


string saveHtml = "<html>" +

    "<head>" +

    "  <title>Select Image</title>" +

    "  <script type=\"text/javascript\">" +

    "  function displayImage(elem) {" +

    "    var image = document.getElementById(\"canvas\");" +

    "    image.src = elem.value;        " +

    "  }" +

    "  </script>" +

    "</head>" +

    "<body>" +

    "  <form name=\"controls\">" +

    "    <img id=\"canvas\" src=\"pictures/fire1.jpg\" />" +

    "    <select name=\"imageList\" onchange=\"displayImage(this);\">" +

    "      <option value=\"pictures/001JRPchargeable.png\">Fire 1</option>" +

    "      <option value=\"pictures/001JRPNonchargeable.png\">Fire 2</option>" +

"</select>" +

"  </form>" +

"</body>" +

"</html>";



string path = @"D:\Test.html";

System.IO.File.WriteAllText(path, saveHtml)


查看完整回答
反對 回復 2023-09-04
  • 2 回答
  • 0 關注
  • 196 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號