xmlhttprequest和innerhtml执行javascript [英] xmlhttprequest and innerhtml executing javascript

查看:63
本文介绍了xmlhttprequest和innerhtml执行javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用xmlhttprequest和innerhtml在div标签之间将html发布到我的主页面上。我发布的html有javascript,我正在使用eval()函数执行。但是,我面临的问题是javascript也使用innerhtml,并且由于某种原因不起作用。我已经测试了javascript,它肯定正在执行,它只是不会改变innerhtml。


为了更清楚,innerhtml试图访问我发布到我的html主页。所以到目前为止发生的事情是:


获取HTML

在div标签之间发布HTML

eval javascript

和现在的innerhtml应该改变


提前致谢!

John

解决方案

只是碰到消息


我在使用xmlhttprequest和innerhtml的div标签之间将html发布到我的主页面上。我发布的html有javascript,我正在使用eval()函数执行。但是,我面临的问题是javascript也使用innerhtml,并且由于某种原因不起作用。我已经测试了javascript,它肯定正在执行,它只是不会改变innerhtml。


为了更清楚,innerhtml试图访问我发布到我的html主页。所以到目前为止发生的事情是:


获取HTML

在div标签之间发布HTML

eval javascript

现在innerhtml应该改变


提前致谢!

John


< blockquote>嗨...


请举例说明你在做什么...


你正在给div写文字这段文字包含js ......对吧?现在你解析那个文本并评估js ......对吗? evaled js使用相同的文本? ...也许你简化你的代码并在这里发布一个例子......这样我们就可以仔细看看它了。


亲切的问候......


在我的主文件中,在DIV TAGS之间发布下面的HTML / JS,有一个脚本在xmlhttprequest之后运行JS。在下面的JS中,有一行需要访问元素lg1的innerHTML。但是,这不会显示在页面上。有什么想法吗?

SHOP.HTML

[HTML]< body>

< link rel =" ;样式表"类型= QUOT;文本/ CSS" HREF =" screen.css" />


< script type =" text / javascript">

var s = document.createElement(''script'');

s.src =''yahoo.js'';

document.body.appendChild(s);

...<执行更多脚本>

< / script>

< / body>


< script type =" ; text / javascript">


YAHOO.example.DDApp = function(){

return {

init:function (){

var eul = document.getElementById(" lg1");

var eli = document.createElement(" li");

// eli.appendChild(document.createTextNode(" WSJ.com"));

eli.innerHTML ="< image src =''barrons.jpg''/> ;" ;;

eli.id =" test";

eli.setAttribute(" class"," sortList");

eli.setAttribute(" className"," sortList");

eli.price = 19.99

eul.appendChild(eli);


new YAHOO.example.DDList(" test");


new YAHOO.example.DDListBoundary(" hidden1");

new YAHOO.example.DDListBoundary(" hidden2");

new YAHOO.example。 DDListBoundary(QUOT; hidden3");

}

};

}();

YAHOO.util.DDM.mode = YAHOO.util .DDM.INTERSECT; //将模式设置为Intersect,在目标上拖放时提供更多自由度

YAHOO.util.Event.addListener(window,load,YAHOO.example.DDApp.init);

< / script>


< td>

< ul id =" lg1" class =" listGroup1">产品

...

< / ul>

< / td>

...

< / div>

[/ HTML]



嗨...


请举例说明你在做什么...


你正在写文字到一个div,这个文本包含js ...对吗?现在你解析那个文本并评估js ......对吗? evaled js使用相同的文本? ...也许你简化你的代码并在这里发布一个例子......这样我们就可以仔细看看它了。


亲切的问候......

I am posting html onto my main page between div tags using xmlhttprequest and innerhtml. The html I am posting has javascript inside which I am executing using the eval() function. However, the problem I face is that the javascript uses innerhtml as well and will not work for some reason. I have tested the javascript and it is definitely executing, it just will not change the innerhtml.

To be more clear, the innerhtml is trying to access the html that I am posting onto my main page. So what is happening so far is:

Get HTML
POST HTML between div tags
eval javascript
and now innerhtml should change

Thanks in advance!
John

解决方案

Just bumping the message up

I am posting html onto my main page between div tags using xmlhttprequest and innerhtml. The html I am posting has javascript inside which I am executing using the eval() function. However, the problem I face is that the javascript uses innerhtml as well and will not work for some reason. I have tested the javascript and it is definitely executing, it just will not change the innerhtml.

To be more clear, the innerhtml is trying to access the html that I am posting onto my main page. So what is happening so far is:

Get HTML
POST HTML between div tags
eval javascript
and now innerhtml should change

Thanks in advance!
John


hi ...

please give an example on what you are doing ...

you are writing text to a div and this text contains js ... right? now you parse that text and eval the js ... right? the evaled js uses the same text where it is in? ... perhaps you simplify your code and post an example here ... so that we may have a closer look on it.

kind regards ...


In my main file where the HTML/JS below is being posted beteween DIV TAGS, there is a script to run the JS after the xmlhttprequest. In the JS below there is a line that needs to access the innerHTML of the element "lg1". However, this will not display on the page. Any ideas?

SHOP.HTML
[HTML]<body>
<link rel="stylesheet" type="text/css" href="screen.css" />

<script type="text/javascript">
var s = document.createElement(''script'');
s.src = ''yahoo.js'';
document.body.appendChild(s);
...<execute a few more scripts>
</script>
</body>

<script type="text/javascript">

YAHOO.example.DDApp = function() {
return {
init: function() {
var eul = document.getElementById("lg1");
var eli = document.createElement("li");
// eli.appendChild(document.createTextNode("WSJ.com") );
eli.innerHTML = "<image src=''barrons.jpg'' />";
eli.id = "test";
eli.setAttribute("class", "sortList");
eli.setAttribute("className", "sortList");
eli.price = 19.99
eul.appendChild(eli);

new YAHOO.example.DDList("test");

new YAHOO.example.DDListBoundary("hidden1");
new YAHOO.example.DDListBoundary("hidden2");
new YAHOO.example.DDListBoundary("hidden3");
}
};
} ();
YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT; //Sets the mode to Intersect which provides more freedom when dragging and dropping on a target
YAHOO.util.Event.addListener(window, "load", YAHOO.example.DDApp.init);
</script>

<div id="update">
<td>
<ul id="lg1" class="listGroup1">Products
...
</ul>
</td>
...
</div>
[/HTML]


hi ...

please give an example on what you are doing ...

you are writing text to a div and this text contains js ... right? now you parse that text and eval the js ... right? the evaled js uses the same text where it is in? ... perhaps you simplify your code and post an example here ... so that we may have a closer look on it.

kind regards ...


这篇关于xmlhttprequest和innerhtml执行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆