动态等价? [英] dynamic equivalent ?

查看:50
本文介绍了动态等价?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如图所示:


< script Language =" javascript" src =" http://127.0.0.1/syndicate.ashx?d =供应商">< / script>


有没有办法以编程方式设置src ??

this works as shown:

<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>

is there a way to set src programmatically ??

推荐答案



Jon Paal写道:

Jon Paal wrote:

这是有效的如图所示:


< script Language =" javascript" src =" http://127.0.0.1/syndicate.ashx?d =供应商">< / script>


有没有办法以编程方式设置src?
this works as shown:

<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>

is there a way to set src programmatically ??



它以我自己的库为例,但这对我有用:


< html>


< body>

< script id =" script1" type =" text / javascript">< / script>

< script type =" text / javascript">

文件。 getElementById(" script1")。s​​rc =" /Ajax/ajax.js" ;;

< / script>


< script type = " text / javascript">

var ajax = new AjaxRequest();

ajax.doTextRequest(" http://www.google。 com"," GET","",update,true);


function update(){

document.getElementById(" goog" ;)。innerHTML = ajax.getValue();

}

< / script>


< div id = " goog">< / div>

< / body>


< / html>

It uses my own library as an example, but this did work for me:

<html>

<body>
<script id="script1" type="text/javascript"></script>

<script type="text/javascript">
document.getElementById("script1").src="/Ajax/ajax.js";
</script>

<script type="text/javascript">
var ajax = new AjaxRequest();

ajax.doTextRequest("http://www.google.com", "GET", "", update, true);

function update() {
document.getElementById("goog").innerHTML = ajax.getValue();
}
</script>

<div id="goog"></div>
</body>

</html>




i希望得到类似下面的东西,但是当src是动态的时候它并没有返回任何东西。只有当src在

时,才会显示工作页面加载时的脚本标记。


============ ========================

< script Language =" javascript" >


函数switchsrc(id){

var mysrc;

switch(id)

{

案例1:

// alert(1);

mysrc =" suppliers";

break;

case 2:

// alert(2);

mysrc =" customers";

break;

}


document.getElementById(" ashx")。s​​rc =" http://127.0.0.1/syndicate.ashx ?d =" + mysrc;

}


< / script>< br>


< script type = "文本/ JavaScript的" ID = QUOT; ASHX" >< / script>


=============================== =================

" Tom Cole" < tc **** @ gmail.com在消息新闻中写道:11 ********************** @ m7g2000cwm.googlegro ups.com ...

i was hoping to get to something like below, but it doesn''t return anything when src is dynamic. Only seems to work when src is in
the script tag at the time page is loaded.

====================================

<script Language="javascript" >

function switchsrc(id){
var mysrc;
switch (id)
{
case 1:
//alert (1);
mysrc = "suppliers";
break;
case 2:
//alert (2);
mysrc = "customers";
break;
}

document.getElementById("ashx").src = "http://127.0.0.1/syndicate.ashx?d=" + mysrc ;
}

</script><br>

<script type="text/javascript" id="ashx" ></script>

================================================

"Tom Cole" <tc****@gmail.comwrote in message news:11**********************@m7g2000cwm.googlegro ups.com...

>

Jon Paal写道:
>
Jon Paal wrote:

>这如图所示:

< script Language =" javascript" src =" http://127.0.0.1/syndicate.ashx?d =供应商">< / script>

有没有办法以编程方式设置src?
>this works as shown:

<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>

is there a way to set src programmatically ??



它以我自己的库为例,但这对我有用:


< html>


< body>

< script id =" script1" type =" text / javascript">< / script>

< script type =" text / javascript">

文件。 getElementById(" script1")。s​​rc =" /Ajax/ajax.js" ;;

< / script>


< script type = " text / javascript">

var ajax = new AjaxRequest();

ajax.doTextRequest(" http://www.google。 com"," GET","",update,true);


function update(){

document.getElementById(" goog" ;)。innerHTML = ajax.getValue();

}

< / script>


< div id = " goog">< / div>

< / body>


< / html>


It uses my own library as an example, but this did work for me:

<html>

<body>
<script id="script1" type="text/javascript"></script>

<script type="text/javascript">
document.getElementById("script1").src="/Ajax/ajax.js";
</script>

<script type="text/javascript">
var ajax = new AjaxRequest();

ajax.doTextRequest("http://www.google.com", "GET", "", update, true);

function update() {
document.getElementById("goog").innerHTML = ajax.getValue();
}
</script>

<div id="goog"></div>
</body>

</html>



Tom Cole在2006年9月25日下午4:11发表以下内容:
Tom Cole said the following on 9/25/2006 4:11 PM:

Jon Paal写道:
Jon Paal wrote:

>如图所示:

< script Lan瓜哥= QUOT; JavaScript的" src =" http://127.0.0.1/syndicate.ashx?d =供应商">< / script>

有没有办法以编程方式设置src?
>this works as shown:

<script Language="javascript" src="http://127.0.0.1/syndicate.ashx?d=suppliers"></script>

is there a way to set src programmatically ??



它使用我自己的库作为示例,但这对我有用:


It uses my own library as an example, but this did work for me:



你有没有在IE以外的任何地方测试它?你应该在那里进行测试,因为

只允许更改脚本的.src属性的UA

元素是IE。


虽然动态创建脚本元素得到了广泛支持,但是你只需要创建元素(''script'')然后将它的'.text属性设置为

脚本块。

-

兰迪

机会有利于准备好的心灵

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /

Did you test it in anything besides IE? You should test it there as the
only UA that allows the changing of the .src property of a script
element is IE.

Although dynamically creating script elements is very widely supported,
you simply createElement(''script'') and then set it''s .text property to
the script block.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


这篇关于动态等价?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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