<script>
function fun(){alert('ok')};
str="<input onclick='alert(this.value);fun()' value='i am ok'>xxxxxx...</font>......."
document.write(str)
</script>
function fun(){alert('ok')};
str="<input onclick='alert(this.value);fun()' value='i am ok'>xxxxxx...</font>......."
document.write(str)
</script>
楼上的,要写入<script>…………</script>。
<script language=javascript>
str = "function fun() {alert('fun fun fun!');} fun();";function window.onload()
{
var s = document.createElement("script");
s.defer = true;
s.type="text/javascript";
s.text = str;
//document.all("dv").appendChild(s);
// or
document.body.appendChild(s);
}
</script>
<div id="dv"></div>2. create an iframe and write the string into it, for example:
<script language=javascript>
str="<script language=javascript id='js1'>function fun() {alert('fun fun fun!');} fun();<\/script><font color='red'>xxxxxx...<\/font>.......";function window.onload()
{
var ifr = document.createElement("IFRAME");
ifr.name="ifr";
ifr.id="ifr";
document.body.appendChild(ifr);
frames["ifr"].document.open();
frames["ifr"].document.write(str);
frames["ifr"].document.close();}
</script>3. or replace the current window, for example:
<script language=javascript>
str="<script language=javascript id='js1'>function fun() {alert('fun fun fun!');} fun();<\/script><font color='red'>xxxxxx...<\/font>.......";function replaceDoc()
{
document.open();
document.write(str);
document.close();
}
</script>
<input type="button" value="replace" onclick="replaceDoc()">
response.write str1
而 str1="<script language=javascipt>
document.writeln(str);
</script>"
我想在str中实现函数调用的功能,不知道怎么写!希望高手能给予指点!