客户端函数为何加上变量就不能执行了呢? tryResponse.Write("<body onload=init('on','" + t + "')>"); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 思归大侠,不行啊,只要加上HTML标签就出错,Response.Write("<body onload=init('on','<h1>hello<h1>')>");这样就出错。是不是JS代码的问题?我把JS代码检查了好几遍就是没找出什么地方出错了。以下是这段JS代码:function init(Model,Html) { Editor.document.designMode=Model; if(Html !="") initHTML = Html; Editor.document.open(); Editor.document.write(initHTML); Editor.document.close(); initHTML = "";}怎么会这么奇怪? 咋把俺给晾着了?思归?imfine?去哪了?俺把全部家底都押上求个解成不? Page_Load中可以改变<body>的内容吗? add a "" around init(....):<script language="C#" runat="server">private void Page_Load(object sender, System.EventArgs e){ if(!Page.IsPostBack) { string t = "<h1>hello</h1>"; Response.Write("<body onload=\"init('on','" + t + "')\">"); }}</script><script language="javascript">function init(a,b){ alert(a); alert(b);}</script> 思归大侠,还是不行,这是不是C#的一个BUG呢?看看以下的结果:function init(Model,Html) { Editor.document.designMode=Model; if(Html !="") initHTML = Html; Editor.document.open(); Editor.document.write(initHTML); Editor.document.close(); initHTML = "";}在Load_Page中Response.Write("<body onload=init('on','hello')>");//可以运行Response.Write("<body onload=init('on','<H1>hello</H1>')>");//不能运行string t = "hello";Response.Write("<body onload=\"init('on', + t + ")\">");//不能运行如果将Response.Write("<body onload=\"init('on', + t + ")\">");改为:Response.Write("<body onload=init('on', '')>");将function init(Model,Html)中的:Editor.document.write(initHTML);改为:Editor.document.write('<H1>hello</H1>');就可以运行正常,看来问题好象不在javascript上,而是C#中无法用Response.Write方法将变量赋给客户端,为什么会出现这种情况?真的是搞不懂。有没有替代的其它办法将服务器控件值赋给指定的客户端对象中? string t = "<h1>hello</h1>";Response.Write("<body onload=\"init('on','" + t + "')\">"); ^^^^ ^^^^ ^^^^^^ortrystring t = "<h1>hello</h1>";Response.Write("<body onload=\"init('on',dvhtml.innerHTML)\">");Response.Write("<div id='dvhtml' style='display:none'>" + t + "</div>"); 关于选定dropdownlist中值插入数据库的问题!~!~ 反射中的资源关闭问题 如何获得图片列表内的ICO文件 System.Media.SoundPlayer只控制wav文件中的声波文件,有不有支持多个格式的类? 以前一直在做JAVA,想转C#,作C/S,有没有好一点的书籍参考呀!!谢谢 一个烦死人的问题 大侠过来看看:关于用户控件、定制控件和复合控件 C#调用Godex(科诚)G500条码打印机 一个奇怪的问题 未处理的“System.ArgumentException”类型的异常.大家帮帮忙! 工具条的问题 位运算 给解释下吧
这样就出错。是不是JS代码的问题?我把JS代码检查了好几遍就是没找出什么地方出错了。
以下是这段JS代码:function init(Model,Html)
{
Editor.document.designMode=Model;
if(Html !="")
initHTML = Html;
Editor.document.open();
Editor.document.write(initHTML);
Editor.document.close();
initHTML = "";}怎么会这么奇怪?
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string t = "<h1>hello</h1>";
Response.Write("<body onload=\"init('on','" + t + "')\">");
}
}
</script>
<script language="javascript">
function init(a,b)
{
alert(a);
alert(b);
}
</script>
{
Editor.document.designMode=Model;
if(Html !="")
initHTML = Html;
Editor.document.open();
Editor.document.write(initHTML);
Editor.document.close();
initHTML = "";}在Load_Page中
Response.Write("<body onload=init('on','hello')>");//可以运行Response.Write("<body onload=init('on','<H1>hello</H1>')>");//不能运行string t = "hello";
Response.Write("<body onload=\"init('on', + t + ")\">");//不能运行
如果将Response.Write("<body onload=\"init('on', + t + ")\">");
改为:Response.Write("<body onload=init('on', '')>");将function init(Model,Html)中的:Editor.document.write(initHTML);
改为:Editor.document.write('<H1>hello</H1>');
就可以运行正常,看来问题好象不在javascript上,而是C#中无法用Response.Write方法将变量赋给客户端,为什么会出现这种情况?真的是搞不懂。有没有替代的其它办法将服务器控件值赋给指定的客户端对象中?
Response.Write("<body onload=\"init('on','" + t + "')\">");
^^^^ ^^^^ ^^^^^^
ortrystring t = "<h1>hello</h1>";
Response.Write("<body onload=\"init('on',dvhtml.innerHTML)\">");
Response.Write("<div id='dvhtml' style='display:none'>" + t + "</div>");