1、test.html 測試頁
<html>
<head>
<title>測試頁面</title>
<style>
.list {
border-top:1 solid #8A2BE2;
border-left:1 solid #8A2BE2;
border-right:1 solid #8A2BE2;
}
.list td {
border-bottom: 1 solid #8A2BE2;
}
</style>
<script>
function $(el) {
return document.getElementById(el);
}
function showWin(param) {
window.showModalDialog("dailog.htm", param, "dialogWidth:" +param.width +"px;dialogHeight:"+param.height+"px;center:yes;help:no;scroll:no;status:no;resizable:no");
}
function TB(tbid) {
this.tb = typeof(tbid) == "string"? $(tbid): tbid;
this.getValue = function(rowIndex, cellIndex){
var trs = this.tb.rows[rowIndex];
var _td = trs.cells[cellIndex];
return _td.innerText;
}
this.setValue = function(rowIndex, cellIndex, value) {
var _tr = this.tb.rows[rowIndex];
var _td = _tr.cells[cellIndex];
_td.innerText = value;
}
/********獲取行索引********/
this.findRowIndex = function(eventSrc) {
var _tr = eventSrc; //eventSrc事件源,必須在TD里獲事件源是TD或TR本身
while(_tr.tagName != "TR") {
_tr = _tr.parentNode;
}
var trs = this.tb.rows;
for(var i = 0; i < trs.length; i++){
if(_tr == trs[i]) return i;
}
}
}
function edit() {
var tb = new TB("data");
rIndex = tb.findRowIndex(event.srcElement);
$("updateRowIndex").value = rIndex;
$("userName").value = tb.getValue(rIndex, 1); //獲得姓名
$("sex").value = tb.getValue(rIndex, 2); //獲得性別
$("age").value = tb.getValue(rIndex, 3); //獲得年齡
showWin({title:"修改用戶信息", width:390, height:230, _div:"openWin",parent:window});
}
function saveAndUpdateView(){
var updateRowIndex = $("updateRowIndex").value;
var tb = new TB($f("data")); //$f()在dailog.html定義,獲到的table是父窗口中的table
tb.setValue(updateRowIndex, 1, $("userName").value);
tb.setValue(updateRowIndex, 2, $("sex").value);
tb.setValue(updateRowIndex, 3, $("age").value);
close();
}
</script>
</head>
<body>
<p style="margin-top:60px">
<center>
<table id="data" class="list" width="460px">
<tr>
<td>編號(hào)</td>
<td>用戶名</td>
<td>性別</td>
<td>年齡</td>
<td>操作</td>
</tr>
<tr>
<td>1</td>
<td>李永勝</td>
<td>男</td>
<td>27</td>
<td><span style="background:#FAEBD7;cursor:hand" onclick="edit();"> 修改 </span></td>
</tr>
<tr>
<td>2</td>
<td>林兄</td>
<td>男</td>
<td>27</td>
<td><span style="background:#FAEBD7;cursor:hand" onclick="edit();"> 修改 </span></td>
</tr>
<tr>
<td>3</td>
<td>葉兄</td>
<td>男</td>
<td>23</td>
<td><span style="background:#FAEBD7;cursor:hand" onclick="edit();"> 修改 </span></td>
</tr>
</table>
</center>
</p>
<!---彈出窗口顯示的內(nèi)容---->
<div id="openWin" style="display:none;">
<form>
<fieldSet>
<legend>修改用戶</legend>
<table>
<tr>
<td>用戶名</td><td><input type="text" id="userName"/></td>
</tr>
<tr>
<td>性別</td><td><input type="text" id="sex"/></td>
</tr>
<tr>
<td>年齡</td><td><input type="text" id="age"/></td>
</tr>
</table>
</fieldSet>
<input type="hidden" id="updateRowIndex"/>
</form>
<span style="background:#FAEBD7;cursor:hand" onclick="saveAndUpdateView();"> 修改 </span>
</div>
</body>
</html>
2、dailog.html 窗口原型
<html>
<head>
<script>
var param = window.dialogArguments; //傳過來的模式對(duì)話框窗口參數(shù)
document.title = param.title; //窗口標(biāo)題,必須在窗口創(chuàng)建前實(shí)現(xiàn)s
/********將父窗口的js加載進(jìn)來********/
var scripts = param.parent.document.scripts;
var _head = document.getElementsByTagName("head")[0];
for(var n = 0; n < scripts.length; n++) {
if(scripts[n].src) {
var _script = newEl("script");
_script.src = scripts[n].src;
bind(_head, _script);
}else{//加載直接在html文檔中寫的script
var _script = newEl("script");
_script.text = scripts[n].text;
bind(_head, _script);
}
}
/*******根據(jù)ID獲得父窗口的元素*********/
function $f(el) {
return param.parent.document.getElementById(el);
}
/***********創(chuàng)建一個(gè)HTML元素*******/
function newEl(tagName) {
return document.createElement(tagName);
}
/***********追加元素***************/
function bind(ower, child) {
ower.appendChild(child);
}
/*******在瀏覽器完成對(duì)象的裝載后立即觸發(fā)*********/
window.onload = function() {
var winDiv;
if(typeof(param._div) == "string") {
winDiv = param.parent.document.getElementById(param._div); //父窗口window對(duì)象,因?yàn)閜aram._div對(duì)象在父窗口
}else{//直接傳對(duì)象過來
winDiv = param._div;
}
$("mainDiv").innerHTML = winDiv.innerHTML; //將DIV內(nèi)容在彈出窗口中渲染
}
</script>
</head>
<body>
<center>
<div id="mainDiv" style="margin-top:20px;width:90%"></div>
</center>
</body>
</html>
如需轉(zhuǎn)載,請(qǐng)注明原文出處!謝謝合作。
FeedBack:
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口[未登錄]
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口[未登錄]
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
2008-05-02 22:57 | 無羽蒼鷹
function showWin(param) {
window.showModalDialog("dailog.htm", param, "dialogWidth:" +param.width +"px;dialogHeight:"+param.height+"px;center:yes;help:no;scroll:no;status:no;resizable:no");
}
"dailog.htm",為.htm 不是.html。不好意思! 回復(fù) 更多評(píng)論
window.showModalDialog("dailog.htm", param, "dialogWidth:" +param.width +"px;dialogHeight:"+param.height+"px;center:yes;help:no;scroll:no;status:no;resizable:no");
}
"dailog.htm",為.htm 不是.html。不好意思! 回復(fù) 更多評(píng)論
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口[未登錄]
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
# re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
2009-03-05 15:28 | ll
function showAlbumMsg(album_id){
if(Prototype.Browser.IE){
window.showModelessDialog("/","","dialogHeight=700px;dialogWidth=600px;scroll=yes;resizable=0;status=no");
}
else{
window.open("/","","height=700,width=600,scrollbars=yes,resizable=0,location=no,menubar=no,titlebar=no,toolbar=no");
}
} 回復(fù) 更多評(píng)論
if(Prototype.Browser.IE){
window.showModelessDialog("/","","dialogHeight=700px;dialogWidth=600px;scroll=yes;resizable=0;status=no");
}
else{
window.open("/","","height=700,width=600,scrollbars=yes,resizable=0,location=no,menubar=no,titlebar=no,toolbar=no");
}
} 回復(fù) 更多評(píng)論
只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。 | ||
![]() |
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
|
||
相關(guān)文章:
|
||
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
27 | 28 | 29 | 30 | 1 | 2 | 3 | |||
4 | 5 | 6 | 7 | 8 | 9 | 10 | |||
11 | 12 | 13 | 14 | 15 | 16 | 17 | |||
18 | 19 | 20 | 21 | 22 | 23 | 24 | |||
25 | 26 | 27 | 28 | 29 | 30 | 31 | |||
1 | 2 | 3 | 4 | 5 | 6 | 7 |
常用鏈接
留言簿(3)
隨筆分類
隨筆檔案
文章分類
相冊(cè)
收藏夾
博客好友
搜索
最新評(píng)論

- 1.?re: 用javascript實(shí)現(xiàn)較為通用的客戶端分頁組件
- 評(píng)論內(nèi)容較長,點(diǎn)擊標(biāo)題查看
- --yangxd
- 2.?re: 用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口
-
@fly
沒有東東 - --wudang
- 3.?re: Prototype學(xué)習(xí)志 之 bind方法的“謎”迷人色彩![未登錄]
-
我在IE中提示對(duì)象不支持“bind”屬性或方法
請(qǐng)問這個(gè)是怎么回事呢? - --lc
- 4.?re: 自編 jtle(javascript template language engine) javascript模板語言引擎, 輕松處理json數(shù)據(jù)![未登錄]
- 離技術(shù)越來越遠(yuǎn)了
- --Sonny Li
- 5.?有個(gè)最新版的代碼,分享給大家,也是幾年前寫的東西了
- 評(píng)論內(nèi)容較長,點(diǎn)擊標(biāo)題查看
- --Sonny Li
閱讀排行榜
- 1.?用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口(5467)
- 2.?用javascript實(shí)現(xiàn)較為通用的客戶端分頁組件(3776)
- 3.?請(qǐng)高手解救小弟,萬分感激!使用dom4j如何實(shí)現(xiàn)按Element的某個(gè)屬性排序???(3215)
- 4.?自編 jtle(javascript template language engine) javascript模板語言引擎, 輕松處理json數(shù)據(jù)!(2296)
- 5.?Prototype學(xué)習(xí)志 之 bind方法的“謎”迷人色彩!(1938)
評(píng)論排行榜
- 1.?用javascript實(shí)現(xiàn)較為通用的客戶端分頁組件(23)
- 2.?用"window.showModalDialog()"實(shí)現(xiàn)DIV模式彈出窗口(15)
- 3.?Prototype學(xué)習(xí)志 之 bind方法的“謎”迷人色彩!(6)
- 4.?請(qǐng)高手解救小弟,萬分感激!使用dom4j如何實(shí)現(xiàn)按Element的某個(gè)屬性排序???(5)
- 5.?自編 jtle(javascript template language engine) javascript模板語言引擎, 輕松處理json數(shù)據(jù)!(4)