请问一下怎么在一个JS方法里调用另外一个JS方法,如JS1
<script language="javascript" type="text/javascript">
function showBig<%#Eval("Id") %>()
{
var bigsrc='<%#Eval("ProAdress") %>';
var bigImg = document.createElement("IMG");
bigImg.src=bigsrc;
bigImg.onload="此处要怎么写?"
var digDiv = document.getElementById("bigDIV");
digDiv.innerHTML="";
var Title = document.getElementById('<%#Eval("id") %>').alt;
A.innerText = Title;
digDiv.appendChild(bigImg);
}
</script>
JS2
<script language="javascript" type="text/javascript">
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
} </script>用JS1调用JS2 ,在JS1里面定义img 的onload事件?
<script language="javascript" type="text/javascript">
function showBig<%#Eval("Id") %>()
{
var bigsrc='<%#Eval("ProAdress") %>';
var bigImg = document.createElement("IMG");
bigImg.src=bigsrc;
bigImg.onload="此处要怎么写?"
var digDiv = document.getElementById("bigDIV");
digDiv.innerHTML="";
var Title = document.getElementById('<%#Eval("id") %>').alt;
A.innerText = Title;
digDiv.appendChild(bigImg);
}
</script>
JS2
<script language="javascript" type="text/javascript">
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
} </script>用JS1调用JS2 ,在JS1里面定义img 的onload事件?
解决方案 »
- dw中,要求这样查找字符.正则表达式怎么写呢?
- 一段鼠标拖动层移动的JS,帮忙修改下bug
- 如何focus在textbox中最后一个字符的后面
- javascript有没有相当与ASP中的Split( Str ,"," )函数?
- 把javascript中值用<div id="name"></div>的方式显示到网页中,如何把name的值赋给PHP变量呢?
- js获取cookie 的小问题求指教
- 一个很有趣的问题!!!!!
- javascript能像C++一样支持名称空间吗?
- 该如何实现这个效果,请高手指教
- js获取gridview某行指定的值
- jquery调用load()函数,刷新后无效问题
- 前辈们可否推荐一些Javascript入门书籍?
2.js1和js2隶属于同1个html第一种情况,如果js1是子窗口 调用的话用parent.方法第二种情况,直接调用
可是错了
var a=10;因为a在你没声明之前就调用了,所以这里是undefine,你要写成var a=10;
alert(a);
你这个问题是一样的道理,你调用DrawImage()方法的时候可能你的DrawImage那个js还没有运行(就是加载)到,所以这个时候方法为空,报错
需要加如关键字 defer ,保证加载完成 <script language="javascript" src="" defer>