<script>
    function showimage(){document.images.showimages.src="<%=imdeximg%>"+document.form.sex.options[document.form.sex.selectedIndex].value+""+document.form.img.options[document.form.img.selectedIndex].value+".gif";}
</script>
问题:这个函数实现的是“根据不同的性别列出不同的小图片,供浏览者选择.”的功能。但是怎么用啊,直接调用该函数就可以显示图片吗?给个例子

解决方案 »

  1.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
    <% string imdeximg = "images/"; %>
        <script type="text/javascript">
        function showimage(){
        
            document.images.showimages.src="<%=imdeximg%>"+document.form.sex.options[document.form.sex.selectedIndex].value+""+document.form.img.options[document.form.img.selectedIndex].value+".gif";
            //alert("<%=imdeximg%>"+document.form1.sex.options[document.form1.sex.selectedIndex].value+""+document.form1.img.options[document.form1.img.selectedIndex].value+".gif");
            }     </script></head>
    <body>
        <form id="form1" runat="server">
            <select id="sex">
                <option value="0">0</option>
                <option value="1">1</option>
            </select>
            <select id="img">
                 <option value="0">0</option>
                 <option value="1">1</option>
            </select>
            <img id="showimages" src="" /><input id="Button1" type="button" value="button" onclick="showimage();" />
        </form>
    </body>
    </html>
      

  2.   

    c#我不会用,有没有JAVAscript的,谢谢
      

  3.   

    用VBscript也行啊,你给的代码运行不起来啊
      

  4.   

    就是用一个select的某些属性组装起来给一个图片的src赋值
      

  5.   

    <%=imdeximg%>是服务器端的变量,javascript是客户端代码,没法写,用jsp,asp,aspx都可以