IFrame的用法
来源:互联网 发布:json.parse出错 编辑:程序博客网 时间:2024/05/17 22:23
IFrame介绍:
<iframe>也应该是框架的一种形式,iframe和frame比较相似,但是有一个根本的区别,iframe可以活动,而frame是不可活动的。换句话说,iframe可以指定其坐标位置。
大部分的时候我们用iframe去模拟一些特效。例如我现在要求当前页面执行某个操作,而操作后肯定要有一个跳转的动作。但是一旦跳转,原始页面就没了,这个时候可以让iframe内部做跳转,这样页面不动,而执行的内容也完成了。如果iframe的尺寸是个0*0的,就可以模拟ajax的效果了。
Frame简单介绍:
在JAVA中,frame是一种控件,可作为父窗体加载其他swing控件。
在VB中,Frame是一种控件。Frame 控件为控件提供可标识的分组。Frame 可以在功能上进一步分割一个窗体-例如,把 OptionButton 控件分成几组。
一,Iframe标记的使用格式是:
代码如下:
<Iframe src="URL" width="x" height="x" scrolling="[OPTION]" frameborder="x"></iframe>
src:文件的路径,既可是HTML文件,也可以是文本、ASP等;
width、height:"画中画"区域的宽与高;
scrolling:当SRC的指定的HTML文件在指定的区域不显不完时,滚动选项,如果设置为NO,则不出现滚动条;如为Auto:则自动出现滚动条;如为Yes,则显示;
FrameBorder:区域边框的宽度,为了让“画中画“与邻近的内容相融合,常设置为0。
例如:
代码如下:
<Iframe src="http://www.jb51.net";; width="250" height="200" scrolling="no" frameborder="0"></iframe>
二、父窗体与子窗体之间的相互控制
在脚本语言与对象层次中,包含Iframe的窗口我们称之为父窗体,另一个为子窗体,弄清这两者的关系很重要,因为要在父窗体中访问子窗体或相反都必须清楚对象层次,才能通过程序来访问并控制窗体。
1、在父窗体中访问并控制子窗体中的对象
在父窗体中,Iframe即子窗体是document对象的一个子对象,可以直接在脚本中访问子窗体中的对象。
代码如下:
<Iframe src="test.htm" id="test" width="250" height="200" scrolling="no" frameborder="0"></iframe> test.htm文件代码为: <html> <body> <h1 id="myH1">hello,my boy</h1> </body> </html>
如我们要改变ID号为myH1的H1标记里的文字为hello,my dear,则可用:
document.myH1.innerText="hello,my dear"(其中,document可省)
document.myH1.innerText="hello,my dear"
另一种使用方式:
<iframe id="myframe" width="100%" class="hide" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" src="StuRecords.aspx" style="display: inline; height: 450px;" runat="server"> </iframe>
当加载父窗体时,默认同时加载子窗体(此时子窗体为空),但是当触发父窗体的某个事件时,要激发子窗体的事件,显示内容
/// <summary> /// 显示某道试题的答题记录,显示某一部分。 /// </summary> /// <param name="dtOneQuestionRecords">查询出20条答题记录</param> /// <param name="pageIndex">为0</param> private void ShowAnswerRecord(DataTable dtOneQuestionRecords, string tableRecord, int pageIndex) { myframe.Attributes["src"] = "StuRecords.aspx"; } /// <summary> /// 下一批 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnNextPage_Click(object sender, EventArgs e) { myframe.Attributes["src"] = "StuRecords.aspx"; }
子窗体的判断
/// <summary>/// 窗体加载时,判断session的值是否为空,空则加载子窗体空白页,否则执行子窗体的事件/// </summary>/// <param name="sender"></param>/// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { if (Session["questionType"] != null) { ShowStuRecord(); } else { } } public void ShowStuRecord() { //得到试题id int questionIndex = Convert.ToInt32(Session["questionIndex"]); //获取考试id值 //string ExamID = DropExam.SelectedItem.Value; string ExamID = "1306172117"; //查找试题记录--答题记录表 string tableRecord = Convert.ToString(Session["tableRecord"]); //题型的value //string UserName = Session["UserName"].ToString(); string UserName = "xvshu"; string questionType = Session["questionType"].ToString(); //调用王永俊的方法,查看答题记录前20条,并写入教师姓名 Hashtable map = new Hashtable(); map.Add("TableNameRecord", tableRecord);//题型value和表名 map.Add("QuestionType", questionType); map.Add("Teacher", UserName); map.Add("QuestionID", questionIndex); map.Add("ExamID", ExamID); QuestionContextBLL awardingBLL = new QuestionContextBLL(map); //查出答题记录 DataTable dtOneQuestionRecords = awardingBLL.SelectRecordTopbyQuestionID(map); if (dtOneQuestionRecords.Rows.Count == 0) { MessageBox.Show(this, "已判完!"); } lblFraction.Text = "标准分数:" + Session["Fraction"]; int pageIndex = 0; for (int i = 30 * pageIndex; i < 30 * pageIndex + 30 && i < dtOneQuestionRecords.Rows.Count; i++) { //显示答写的试题答案 TableCell tc = new TableCell(); tc.Text = (i + 1).ToString() + "答案:" + dtOneQuestionRecords.Rows[i]["ExamAnswer"].ToString(); TableRow tr = new TableRow(); tr.Cells.Add(tc); tblAutoTable.Rows.Add(tr); TextBox textBox = new TextBox(); //得到试题记录的id号 string id = dtOneQuestionRecords.Rows[i]["ID"].ToString(); textBox.Text = dtOneQuestionRecords.Rows[i]["Fraction"].ToString(); //给评分控件设置id号 textBox.ID = tableRecord.Trim() + dtOneQuestionRecords.Rows[i]["ID"].ToString(); textBox.Attributes.Add("Onblur", "javascript:return CheckFraction(event.srcElement)&&JudgeQuestions('" + tableRecord.Trim() + "','" + id + "','" + textBox.ID + "')"); //textBox.Attributes.Add("Onblur", "javascript:test()"); TableCell tc1 = new TableCell(); tc1.Controls.Add(textBox); TableRow tr1 = new TableRow(); tr1.Cells.Add(tc1); tblAutoTable.Rows.Add(tr1); //Session["txtScores"] = textBox.ID; } }
在这里的应用主要是根据id值来加载子页面!当然我们也可以根据id值来对它进行不同的操作。
2、在子窗体中访问并控制父窗体中对象
在子窗体中我们可以通过其parent即父(双亲)对象来访问父窗口中的对象。
复制代码代码如下:
<html> <body onclick="alert(tt.myH1.innerHTML)"> <Iframe name="tt" src="frame1.htm" width="250" height="200" scrolling="no" frameborder="0"></iframe> <h1 id="myH2">hello,my wife</h1> </body> </html>
如果要在myframe操作我们可以这样写:
parent.myframe.innerText="hello,myfriend"
这里parent对象就代表当前窗体(example.htm所在窗体),要在子窗体中访问父窗体中的对象,无一例外都通过parent对象来进行。
总结:通过Iframe标记,我们可将那些不变的内容以Iframe来表示,这样,不必重复写相同的内容(框架),这有点象程序设计中的过程或函数,减省了多少繁琐的手工劳动!另外,至关重要的是,它使页面的修改更为可行,因为,不必因为版式的调整而修改每个页面,你只需修改一个父窗体的版式即可了。
- 很多用法的iframe
- Iframe的用法
- iFrame的用法
- iframe的用法
- iframe的用法
- iframe的简单用法
- iframe的用法
- iframe的用法
- iframe的用法_files
- iframe的用法
- html的iframe用法
- iframe的用法总结
- iframe的用法
- iframe的用法
- IFrame的用法
- iframe的用法
- Iframe用法以及IFRAME标签的使用
- iframe嵌入网页的用法
- 调试在64位Debian上编译好的Linux 0.11(一)
- textBox换行问题
- (六)02机房收费系统数据要求说明书
- 对C++中继承的一些总结
- 善用科技–通过软件来提升你的效率
- IFrame的用法
- Windows 7下安装Osmosis以及简单的使用例子
- 大数据量与高并发
- Sample 3.4:hexoct2.cpp
- 从sd卡获取一个drawable
- 杭电 1025
- 设置vc++控制台程序字体颜色
- OpenCV中的assert函数
- oc基础知识:属性、协议和分类