我有一个 WebBrowser (WinPhone C#),我在 CodeBehind 中设置了 NavigateToString。完整的代码在这里:
string f = "<!DOCTYPE HTML PUBLIC ' -//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><?xml version='1.0' encoding='UTF-8' standalone='yes'?><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' ><script type='text/javascript'>function get_radio_value(test){ var elements = document.getElementsByName(test); for (var i=0; i < elements.length; i++){if (elements[i].checked){var rad_val = elements[i].value;return rad_val;}}}</script><title>Kundenfragebogen</title></head><body><h1>Kundenfragebogen</h1><form name='myForm' action=''><table border='2'><tr><td></td><td>sehr gut</td><td>gut</td><td>schlecht</td></tr><tr><td>Wie geht es Ihnen?</td><td><input type='radio' name='1' value='1'/>Mir ging es noch nie besser!</td><td><input type='radio' name='1' value='2'/>Es geht mir so wie immer.</td><td><input type='radio' name='1' value='3'/>Heute geht einfach gar nichts…</td></tr><tr><td>Können Sie Auto fahren?</td><td><input type='radio' name='2' value='1'/>Ja</td><td></td><td><input type='radio' name='2' value='3'/>Nein</td></tr><tr><td>Möchten Sie unseren Newsletter abonnieren?</td><td><input type='radio' name='3' value='1'/>Ja</td><td></td><td></td></tr></table></form></body></html>";
webbrowser.NavigateToString(f);
当我这样做时,WebBrowser 只显示代码而不是实际的 HTML 站点(带有 RadioButtons,...)。当我这样做时:
string f = "\"<!DOCTYPE HTML PUBLIC ' -//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><?xml version='1.0' encoding='UTF-8' standalone='yes'?><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' ><script type='text/javascript'>function get_radio_value(test){ var elements = document.getElementsByName(test); for (var i=0; i < elements.length; i++){if (elements[i].checked){var rad_val = elements[i].value;return rad_val;}}}</script><title>Kundenfragebogen</title></head><body><h1>Kundenfragebogen</h1><form name='myForm' action=''><table border='2'><tr><td></td><td>sehr gut</td><td>gut</td><td>schlecht</td></tr><tr><td>Wie geht es Ihnen?</td><td><input type='radio' name='1' value='1'/>Mir ging es noch nie besser!</td><td><input type='radio' name='1' value='2'/>Es geht mir so wie immer.</td><td><input type='radio' name='1' value='3'/>Heute geht einfach gar nichts…</td></tr><tr><td>Können Sie Auto fahren?</td><td><input type='radio' name='2' value='1'/>Ja</td><td></td><td><input type='radio' name='2' value='3'/>Nein</td></tr><tr><td>Möchten Sie unseren Newsletter abonnieren?</td><td><input type='radio' name='3' value='1'/>Ja</td><td></td><td></td></tr></table></form></body></html>";
webbrowser.NavigateToString(f);
它正在工作!我只在开头设置了 \"。页面正在显示,但 " 就在我的网站顶部。为什么 f... 我必须在“html-file”的字符串开头写 \" 吗?
编辑:这个更短,但同样的问题:
不工作:
string f = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><?xml version='1.0' encoding='UTF-8' standalone='yes'?><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' ><title>Kundenfragebogen</title></head><body><h1>Kundenfragebogen</h1>asdas</body></html>";
webbrowser.NavigateToString(f);
在职的:
string f = "\"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><?xml version='1.0' encoding='UTF-8' standalone='yes'?><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' ><title>Kundenfragebogen</title></head><body><h1>Kundenfragebogen</h1>asdas</body></html>";
webbrowser.NavigateToString(f);