标题:JavaScript在form表单里面不能运行
只看楼主
浩天
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-11-17
结帖率:80%
已结贴  问题点数:10 回复次数:8 
JavaScript在form表单里面不能运行
我把页面代码贴出来:

myimg-1.1.js 代码:

var MyImg = {
   
    img : [],
    imglink : [],
    imgalt : [],
   
    num : -1,
    time : 5000,
   
    $ : function(id) {
        return document.getElementById(id);
    },
    init : function(img, imglink, imgalt, time) {
        this.img = img;
        this.imglink = imglink;
        this.imgalt = imgalt;
        if(time && time != 0 && time != '0') this.time = time;
    },
    show : function(idx) {
        if(document.all) {
            myimgRotator.filters.revealTrans.Transition = Math.floor(Math.random() * 20);
            myimgRotator.filters.revealTrans.apply();
        }
        document.images.myimgRotator.src = this.img[idx];
        document.images.myimgRotator.alt = this.imgalt[idx];
        if(document.all) myimgRotator.filters.revealTrans.play();
        for(var i=0;i<this.img.length;i++) {
            var o = this.$('myimg_a_' + i);
            if(i == idx) {
                o.style.backgroundColor = 'red';
                o.innerHTML = '&nbsp;<font color=#ffffff>' + (i+1) + '</font>&nbsp;';
            } else {
                o.style.backgroundColor = '';
                o.innerHTML = '&nbsp;' + (i+1) + '&nbsp;';
            }
        }
        this.$('myimgalt').innerHTML = '&nbsp;<a href="javascript:MyImg.linkURL();" style="text-decoration:none;color:blue;">' + (this.imgalt && this.imgalt[idx] ? this.imgalt[idx] : '') + '</a>';
    },
    next : function() {
        this.num++;
        if(this.num >= this.img.length) this.num = 0;
        this.show(this.num);
        setTimeout("MyImg.next()", this.time);
    },
    slct : function(idx) {
        this.num = idx - 1;
        var tmp = this.time;
        this.time = 1000000;
        this.show(idx);
        this.time = tmp;
    },
    linkURL : function() {
        var url = (this.imglink && this.imglink[this.num]) ? this.imglink[this.num] : this.img[this.num];
        window.open(url);
    },
    getHTML : function(img, imglink, imgalt, w, h, time) {
        this.init(img, imglink, imgalt, time);
        w = (w) ? w : 400;
        h = (h) ? h : 300;
        var aa = '';
        for(var i=0;i<this.img.length;i++) {
            aa += '<a id=myimg_a_' + i + ' onclick="MyImg.slct(' + i + ');" style="color:#000;cursor:pointer;" title="' + this.imgalt[i] + '">&nbsp;' + (i+1) + '&nbsp;</a>';
        }
        return '<table boder=0 width=' + w + ' height=' + h + '><tr><td><a href="javascript:MyImg.linkURL();"><img style="FILTER:revealTrans(duration=2,transition=20,border:1px solid #000000" src="' + this.img[0] + '" width=' + w + ' height=' + h + ' border=0 name="myimgRotator" alt=""></a><div style="font-size:13px;margin-top:-30px;"><table border=0 width=' + w + ' bgcolor="#FFFFFF" style="filter:alpha(opacity=80);opacity:0.8;"><tr><td width=50%><div id=myimgalt></div></td><td width=50% align=right>' + aa + '</td></tr></table></div></td></tr></table>';
    },
   
    // ************** 通用调用函数 ******************
    disp : function(img, imglink, imgalt, w, h, time, id) {
        var html = this.getHTML(img, imglink, imgalt, w, h, time);
        if(id) this.$(id).innerHTML = html;
        else document.write(html);
        this.next();
    }
};


 aspx页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head runat="server">
    <title>无标题页</title>


    <script type="text/javascript">
    var img = [
    "imgs/5.jpg",
    "imgs/2.jpg",
    "imgs/3.jpg",
    "imgs/4.jpg",
    "imgs/1.jpg",
    "imgs/6.jpg",
    "imgs/7.jpg",
    "imgs/8.jpg"
    ];
    var imglink = [
    "http://www.baidu.com",
    "http://www.,
    "http://www.,
    "http://www.,
    "http://www.,
    "http://www.baidu.com",
    "http://www.,
    "http://www.
    ];
    var imgalt = [
    "百度",
    "雅虎",
    "QQ",
    "新浪",
    "中国人民",
    "四川",
    "这是大哥",
    "嘿嘿 "
    ];
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>   
    <script type="text/javascript" src="myimg-1.1.js"></script>

        <script type="text/javascript">MyImg.disp(img, imglink, imgalt, 400, 300, 5000);</script>

    </div>
    </form>
</body>
</html>



这代码放到HTML页面运行就一切正常,或者把这里的   <form id="form1" runat="server">这个表单去掉也可以运行,不明白为什么,form表单去掉了其他内容就不晓得改咋写了呢。请高手解答。
搜索更多相关主题的帖子: form 表单 JavaScript 运行 
2010-07-18 16:20
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8074
专家分:6657
注 册:2005-11-7
得分:3 
<script type="text/javascript" src="myimg-1.1.js"></script>
把这句放在<head></head>里

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-07-18 20:46
浩天
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-11-17
得分:0 
兄弟你的解决方案不行哦
2010-07-19 15:31
mujita930
Rank: 1
等 级:新手上路
帖 子:6
专家分:6
注 册:2010-7-19
得分:3 
`````
2010-07-19 16:13
mujita930
Rank: 1
等 级:新手上路
帖 子:6
专家分:6
注 册:2010-7-19
得分:0 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head runat="server">
    <title>无标题页</title>

    <script type="text/javascript" src="myimg-1.1.js"></script>

    <script type="text/javascript">var img = ["imgs/5.jpg","imgs/2.jpg","imgs/3.jpg","imgs/4.jpg","imgs/1.jpg","imgs/6.jpg","imgs/7.jpg","imgs/8.jpg"]; var imglink =["http://www.baidu.com","http://www.,"http://www.,"http://www.,"http://www.,"http://www.baidu.com","http://www.,"http://www.];
var imgalt = ["百度","雅虎","QQ","新浪","中国人民","四川","这是大哥","嘿嘿 "];
    </script>

    <script type="text/javascript">MyImg.disp(img, imglink, imgalt, 400, 300, 5000);</script>

</head>
<body>
    <form id="form1" runat="server">
        <div>
        </div>
    </form>
</body>
</html>
2010-07-19 16:14
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8074
专家分:6657
注 册:2005-11-7
得分:0 
回复 3楼 浩天
照着5层说的那样试试

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-07-19 16:35
浩天
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2007-11-17
得分:0 
以下是引用冰镇柠檬汁儿在2010-7-19 16:35:33的发言:

照着5层说的那样试试



到是有效果了  但是这样我不晓得咋控制这个图片显示的位置了呢  还有就是下面这段js代码到时候也得重cs文件里面数据来不晓得咋控制它在标签里面呢</head>



<script type="text/javascript">var img = ["imgs/5.jpg","imgs/2.jpg","imgs/3.jpg","imgs/4.jpg","imgs/1.jpg","imgs/6.jpg","imgs/7.jpg","imgs/8.jpg"]; var imglink =["http://www.baidu.com","http://www.,"http://www.,"http://www.,"http://www.,"http://www.baidu.com","http://www.,"http://www.];
var imgalt = ["百度","雅虎","QQ","新浪","中国人民","四川","这是大哥","嘿嘿 "];
    </script>
2010-07-19 22:58
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8074
专家分:6657
注 册:2005-11-7
得分:0 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head runat="server">
    <title>无标题页</title>
<script type="text/javascript" src="myimg-1.1.js"></script>
    <script type="text/javascript">
    var img = [
    "imgs/5.jpg",
    "imgs/2.jpg",
    "imgs/3.jpg",
    "imgs/4.jpg",
    "imgs/1.jpg",
    "imgs/6.jpg",
    "imgs/7.jpg",
    "imgs/8.jpg"
    ];
    var imglink = [
    "http://www.baidu.com",
    "http://www.,
    "http://www.,
    "http://www.,
    "http://www.,
    "http://www.baidu.com",
    "http://www.,
    "http://www.
    ];
    var imgalt = [
    "百度",
    "雅虎",
    "QQ",
    "新浪",
    "中国人民",
    "四川",
    "这是大哥",
    "嘿嘿 "
    ];
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>   
        <script type="text/javascript">MyImg.disp(img, imglink, imgalt, 400, 300, 5000);</script>
    </div>
    </form>
</body>
</html>

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-07-19 23:48
misswang
Rank: 8Rank: 8
来 自:湖北荆州
等 级:贵宾
威 望:15
帖 子:265
专家分:720
注 册:2010-3-11
得分:3 
...

misswp2010@
wangping103@
2010-07-20 15:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-313342-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.403088 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved