困扰我两个多星期的问题
<% @ Page Language="C#" %><% @ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Generic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
string strCurrentDir;
//初始化一些数据
if(!Page.IsPostBack)
{
strCurrentDir =Server.MapPath("~/filelist");
lblCurrentDir.Text = strCurrentDir;
tbCurrentDir.Text = strCurrentDir;
}
else
{
strCurrentDir = tbCurrentDir.Text;
tbCurrentDir.Text = strCurrentDir;
lblCurrentDir.Text = strCurrentDir;
}
FileInfo fi;
DirectoryInfo di;
TableCell td;
TableRow tr;
/*
设定Table中的数据
首先搞定第一行
*/
tr = new TableRow();
td = new TableCell();
td.Controls.Add(new LiteralControl("<img src='name.gif'>"));
tr.Cells.Add(td);
td = new TableCell();
td.Controls.Add(new LiteralControl("<img src='size.gif'>"));
tr.Cells.Add(td);
td = new TableCell();
td.Controls.Add(new LiteralControl("<img src='lastmodify.gif'>"));
tr.Cells.Add(td);
tbDirInfo.Rows.Add(tr);
string FileName; //文件名称
string FileExt; //文件扩展名
string FilePic; //文件图片
long FileSize; //文件大小
DateTime FileModify; //文件更新时间
DirectoryInfo dir = new DirectoryInfo(strCurrentDir);
foreach(FileSystemInfo fsi in dir.GetFileSystemInfos())
{
FilePic = "";
FileName = "";
FileExt = "";
FileSize = 0;
if(fsi is FileInfo)
{
//表示当前fsi是文件
fi = (FileInfo)fsi;
FileName = fi.Name;
FileExt = fi.Extension;
FileSize = fi.Length;
FileModify = fi.LastWriteTime;
//通过扩展名来选择文件显示图标
switch(FileExt)
{
case ".gif":
FilePic =FileName;
break;
case ".jpg":
FilePic =FileName;
break;
default:
FilePic = FileName;
break;
}
FilePic="<a href='#'title='test' onmouseover='"+SetPhotoSize();+"'><img src='"+FilePic+"'name='"+photo_single+"' width=25 height=20 alt='"+FileName+"'></a>";
}
else
{
//当前为目录
di = (DirectoryInfo)fsi;
FileName = di.Name;
FileModify = di.LastWriteTime;
FilePic = "<img src='directory.gif' width=25 height=20>";
}
//组建新的行
tr = new TableRow();
td = new TableCell();
td.Controls.Add(new LiteralControl(FilePic+" "+"[sayyes]"+FileName+"[/sayyes]"));
tr.Cells.Add(td);
td = new TableCell();
td.Controls.Add(new LiteralControl(FileSize.ToString()));
tr.Cells.Add(td);
td = new TableCell();
td.Controls.Add(new LiteralControl(FileModify.ToString()));
tr.Cells.Add(td);
tbDirInfo.Rows.Add(tr);
}
}
public List<String> Getphotos()
{
List<String> photos = new List<string>();
string photopath = MapPath("~/filelist/Images");
string[] files = Directory.GetFiles(photopath);
foreach (string photo in files)
photos.Add("~/filelist/Images/" + Path.GetFileName(photo));
return photos;
}
</script>
<html>
<head>
<title></title>
</head>
<script type="text/javascript" language='javascript'>
var orig_height = 100;
var orig_width = 100;
var newWidth = 60;
var newHeight = 80;
function SetPhotoSize() {
document.photo_single.width = orig_width * 4;
document.photo_single.height= orig_height * 4;
}</script>
<script type="text/javascript"language='javascript'>
var orig_height = 100;
var orig_width = 100;
var newWidth = 60;
var newHeight = 80;
function visible1()
{
document.photo_single.width = orig_width;
document.photo_single.height= orig_height/2;
}
</script>
<body >
<form runat="server">
请选择浏览目录后按一下回车键:<asp:TextBox id="tbCurrentDir" runat="server" /><br>
当前目录为:<asp:Label id="lblCurrentDir" runat="server" /><br>
<asp:panel id="panel1" ScrollBars="Both" runat="server" Height="300px" Width="300px">
<asp:Table id="tbDirInfo" Font-Size="9pt" runat="server" BorderStyle="Dashed" />
</asp:panel>
</form>
</body>
</html>
想请各位帮个忙,为什么我在.net中调用javascript中的SetPhotoSize()(红色部分),总是提示找不到这个函数,怎样才能调用这个函数,谢谢! --------------------编程问答-------------------- 0.00%........ --------------------编程问答-------------------- 老兄,能不能发成代码格式的,这样的代码看的很头疼...... --------------------编程问答-------------------- onmouseover='SetPhotoSize();',试下这个。。 --------------------编程问答-------------------- 你就简单的说下 你从哪里去调 页面还是后台? --------------------编程问答-------------------- 发这么多代码,实在看的头晕,到底是什么问题老兄你说清楚下 --------------------编程问答-------------------- 你把script放错地方了,应放在<head></head>标签内 --------------------编程问答-------------------- ID.Attributes.add("onmouseover","SetPhotoSize") --------------------编程问答-------------------- NND的,看见代码我就头疼。 --------------------编程问答--------------------
这个可以随便放吧。。 --------------------编程问答-------------------- 右键看源代码。 --------------------编程问答-------------------- script位置太靠后了,加载先后的问题。代码基本没有什么问题。同意楼上放到head内部吧。 --------------------编程问答-------------------- 你在哪里调用这个脚本的?而且用什么属性调用?属性的选择不同,脚本的存放位置也要有所修改,具体可以看看下面的链接:
script存放在哪里的问题 --------------------编程问答-------------------- JS定义到head里看看 --------------------编程问答-------------------- 谢谢各位,我想要实现当鼠标移动到图片上时图片放大,我再试一下! --------------------编程问答-------------------- 原来不止我一个看得头疼。。。XXX.Attributes.add("onmouseover","SetPhotoSize")
=====================================================================================================
欢迎使用超给力的CSDN论坛专用阅读器:http://download.csdn.net/source/3353776 --------------------编程问答--------------------
人才。。、。 --------------------编程问答-------------------- 怎么把方法调用写到外面去了,要拼在字符串里面,
FilePic="<a href='#'title='test' onmouseover='SetPhotoSize();'><img src='"+....
这样试试吧 --------------------编程问答-------------------- 没看明白,但帮你顶顶 --------------------编程问答--------------------
不错,就是这么做 --------------------编程问答-------------------- 出现以下错误:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误信息: CS0103: 当前上下文中不存在名称“SetPhotoSize”
源错误:
行 90: }
行 91:
行 92: FilePic="<a href='#'title='test' onmouseover='"+SetPhotoSize();+"' onmousedown='"+visible1();+"'><img src='"+FilePic+"'name='"+photo_single+"' width=25 height=20 alt='"+FileName+"'></a>";
行 93:
行 94:
--------------------编程问答-------------------- 试了以上方法都不对
--------------------编程问答-------------------- 不知道跟顺序有关系没有 --------------------编程问答-------------------- 什么顺序 --------------------编程问答-------------------- 我也有同样的问题,我的是在用户控件中Javascript函数调用另一个函数,它不调用另一个函数,求解 --------------------编程问答-------------------- SetPhotoSize();后的分号;去掉
onmouseover='SetPhotoSize()' ><img
--------------------编程问答--------------------
--------------------编程问答-------------------- onmouseover='SetPhotoSize();' --------------------编程问答-------------------- 去掉分号是可以,但是当鼠标指到图片上时,图片没有放大,也就是说没有调用到SetPhotoSize()这个函数 --------------------编程问答-------------------- 也就是说当去掉分号后,SetPhotoSize()被当成一个常量处理,而不是当成一个函数来处理 --------------------编程问答-------------------- 那应该是你的function SetPhotoSize()代码不正确.
FilePic="<a href='#' title='test' onmouseover='SetPhotoSize()'><img src='"+FilePic+"' name='"+photo_single+"' width=25 height=20 alt='"+FileName+"'></a>";
你可以先改为
function SetPhotoSize()
{
alert("ok");
}
试试. --------------------编程问答-------------------- 最后,通过浏览器查看一下网页的源文件.
复制出来给大家看. --------------------编程问答-------------------- 我看了一下是下面这两句话有问题:
document.photo_single.width = orig_width * 4;
document.photo_single.height= orig_height * 4;
不能引用photo_single,不道要怎样引用photo_single --------------------编程问答-------------------- 1.
把img的name属性改为ID
2.引用:
document.getElementById("photo_single").width=400; --------------------编程问答-------------------- 谢谢33楼,已经解决,但是现在的问题是:图片放大只对第一张图片起作用,不知道为什么?以下是源代码:
<% @ Page Language="C#" %>
<% @ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Generic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
string strCurrentDir;
//初始化一些数据
if(!Page.IsPostBack)
{
strCurrentDir =Server.MapPath("~/filelist");
lblCurrentDir.Text = strCurrentDir;
tbCurrentDir.Text = strCurrentDir;
}
else
{
strCurrentDir = tbCurrentDir.Text;
tbCurrentDir.Text = strCurrentDir;
lblCurrentDir.Text = strCurrentDir;
}
FileInfo fi;
DirectoryInfo di;
TableCell td;
TableRow tr;
/*
设定Table中的数据
首先搞定第一行
*/
tr = new TableRow();
td = new TableCell();
td.Controls.Add(new LiteralControl("<img src='name.gif'>"));
tr.Cells.Add(td);
td = new TableCell();
td.Controls.Add(new LiteralControl("<img src='size.gif'>"));
tr.Cells.Add(td);
td = new TableCell();
td.Controls.Add(new LiteralControl("<img src='lastmodify.gif'>"));
tr.Cells.Add(td);
tbDirInfo.Rows.Add(tr);
string FileName; //文件名称
string FileExt; //文件扩展名
string FilePic; //文件图片
long FileSize; //文件大小
DateTime FileModify; //文件更新时间
DirectoryInfo dir = new DirectoryInfo(strCurrentDir);
foreach(FileSystemInfo fsi in dir.GetFileSystemInfos())
{
FilePic = "";
FileName = "";
FileExt = "";
FileSize = 0;
if(fsi is FileInfo)
{
//表示当前fsi是文件
fi = (FileInfo)fsi;
FileName = fi.Name;
FileExt = fi.Extension;
FileSize = fi.Length;
FileModify = fi.LastWriteTime;
//通过扩展名来选择文件显示图标
switch(FileExt)
{
case ".gif":
FilePic =FileName;
break;
case ".jpg":
FilePic =FileName;
break;
default:
FilePic = FileName;
break;
}
FilePic="<a href='#'title='test' onmouseover='SetPhoto()' onmousedown='visible1()'><img src='"+FilePic+"' ID='photo_single' width=25 height=20 alt='"+FileName+"'></a>";
}
else
{
//当前为目录
di = (DirectoryInfo)fsi;
FileName = di.Name;
FileModify = di.LastWriteTime;
FilePic = "<img src='directory.gif' width=25 height=20>";
}
//组建新的行
tr = new TableRow();
td = new TableCell();
td.Controls.Add(new LiteralControl(FilePic+" "+"[sayyes]"+FileName+"[/sayyes]"));
tr.Cells.Add(td);
td = new TableCell();
td.Controls.Add(new LiteralControl(FileSize.ToString()));
tr.Cells.Add(td);
td = new TableCell();
td.Controls.Add(new LiteralControl(FileModify.ToString()));
tr.Cells.Add(td);
tbDirInfo.Rows.Add(tr);
}
}
public List<String> Getphotos()
{
List<String> photos = new List<string>();
string photopath = MapPath("~/filelist/Images");
string[] files = Directory.GetFiles(photopath);
foreach (string photo in files)
photos.Add("~/filelist/Images/" + Path.GetFileName(photo));
return photos;
}
</Script>
<html>
<head>
<script type="text/javascript" language='javascript'>
var orig_height = 100;
var orig_width = 100;
var newWidth = 60;
var newHeight = 80;
function SetPhoto()
{
document.getElementById("photo_single").width= orig_width * 4;
document.getElementById("photo_single").height= orig_height * 4;
}
function visible1()
{
document.getElementById("photo_single").width = orig_width/4;
document.getElementById("photo_single").height= orig_height/5;
}
</script>
<title></title>
</head>
<body>
<form runat="server">
请选择浏览目录后按一下回车键:<asp:TextBox id="tbCurrentDir" runat="server" /><br>
当前目录为:<asp:Label id="lblCurrentDir" runat="server" /><br>
<asp:panel id="panel1" ScrollBars="Both" runat="server" Height="300px" Width="300px">
<asp:Table id="tbDirInfo" Font-Size="9pt" runat="server" BorderStyle="Dashed" />
</asp:panel>
</form>
</body>
</html>
--------------------编程问答-------------------- 大家再帮忙一下,谢谢!
补充:.NET技术 , ASP.NET