查看: 1054|回复: 12
|
请问,怎样可以做到这样的连接?
[复制链接]
|
|
http://developer.apple.com/internet/webcontent/iframe.html(请参考这里)
我想要做一个像它这样的,从A选了,资料在B显示...
我已经把需要的CODE找出来了:
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
var IFrameObj; // our IFrame object
function callToServer(theFormName) {
if (!document.createElement) {return true};
var IFrameDoc;
// We'll build our URL by checking which state
// has been selected in the drop down menu
var stateEl = document.forms[theFormName].state
var theState = stateEl.options[stateEl.selectedIndex].value
if (theState=='') {return false}; // no state has been selected
var URL = "states/"+theState+".html"
//provide a "loading" message
var responseMessage = document.getElementById('responseMessage');
responseMessage.style.display = 'inline';
responseMessage.innerHTML = 'loading data...';
if (!IFrameObj && document.createElement) {
// create the IFrame and assign a reference to the
// object to our global variable IFrameObj.
// this will only happen the first time
// callToServer() is called
try {
var tempIFrame=document.createElement('iframe');
tempIFrame.setAttribute('id','RSIFrame');
tempIFrame.style.border='0px';
tempIFrame.style.width='0px';
tempIFrame.style.height='0px';
IFrameObj = document.body.appendChild(tempIFrame);
if (document.frames) {
// this is for IE5 Mac, because it will only
// allow access to the document object
// of the IFrame if we access it through
// the document.frames array
IFrameObj = document.frames['RSIFrame'];
}
} catch(exception) {
// This is for IE5 PC, which does not allow dynamic creation
// and manipulation of an iframe object. Instead, we'll fake
// it up by creating our own objects.
iframeHTML='<iframe id="RSIFrame" style="';
iframeHTML+='border:0px;';
iframeHTML+='width:0px;';
iframeHTML+='height:0px;';
iframeHTML+='"><\/iframe>';
document.body.innerHTML+=iframeHTML;
IFrameObj = new Object();
IFrameObj.document = new Object();
IFrameObj.document.location = new Object();
IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
IFrameObj.document.location.replace = function(location) {
this.iframe.src = location;
}
}
}
if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
// we have to give NS6 a fraction of a second
// to recognize the new IFrame
setTimeout('callToServer("'+theFormName+'")',10);
return false;
}
if (IFrameObj.contentDocument) {
// For NS6
IFrameDoc = IFrameObj.contentDocument;
} else if (IFrameObj.contentWindow) {
// For IE5.5 and IE6
IFrameDoc = IFrameObj.contentWindow.document;
} else if (IFrameObj.document) {
// For IE5
IFrameDoc = IFrameObj.document;
} else {
return true;
}
IFrameDoc.location.replace(URL);
return false;
}
// handleResponse is passed two parameters when called from the onload
// event of the pages loaded in the hidden IFRAME:
// st: a string indicating which state is being loaded
// doc: the document object of the page loaded in the IFRAME
function handleResponse(st, doc) {
// get a reference to the multiple select list, which we will populate
// with the data from the document loaded in the IFRAME
var namesEl = document.forms.stateForm.zipNames
// clear earlier records from the multiple select list
namesEl.length = 0
// get a reference to the DIV containing the data for this state
var dataEl = doc.getElementById(st)
// get a reference to the collection of the children elements of
// our DIV containing the data (this collection is the DIVs containing
// the actual zip names)
namesColl = dataEl.childNodes
// for easy scripting, assign the number of ZIP names for this state
// to a variable
var numNames = namesColl.length
// iterate through the collection of zip Names and
// create an option element for each one
for (var q=0; q<numNames; q++) {
if (namesColl[q].nodeType!=1) continue; // it's not an element node, let's skedaddle
var str = '' // used to store the text we'll use in the new option
str+= namesColl[q].id + ' ('
// get a reference to the collection of the children elements of
// this DIV (this collection contains the zip codes that fall under this zip name)
var zipsColl = doc.getElementById(namesColl[q].id).childNodes
var numZips = zipsColl.length
// iterate through this collection of zips and each one to the string
for (var r=0; r<numZips; r++) {
if (zipsColl[r].nodeType!=1) continue; // it's not an element node, let's skedaddle
str += zipsColl[r].id + ' '
}
str+= ')'
// create a new option element and add it to the zipNames form element
newOption = new Option(str)
namesEl.options[namesEl.length] = newOption
}
//provide a "success" message
var responseMessage = document.getElementById('responseMessage');
responseMessage.innerHTML = 'loaded records from <a href="'+doc.location+'">this external file<\/a>.';
}
//-->
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<form name="stateForm" id="stateForm" action="server.html">
Select a state from this menu:
<select name="state" onchange="callToServer(this.form.name)">
<option selected value=""></option>
<option value="AL"> Alabama</option>
<option value="AK"> Alaska</option>
<option value="AZ"> Arizona</option>
<option value="AR"> Arkansas</option>
<option value="CA"> California</option>
<option value="CO"> Colorado</option>
<option value="CT"> Connecticut</option>
<option value="DE"> Delaware</option>
<option value="DC"> District of Columbia</option>
<option value="FL"> Florida</option>
<option value="GA"> Georgia</option>
<option value="HI"> Hawaii</option>
<option value="ID"> Idaho</option>
<option value="IL"> Illinois</option>
<option value="IN"> Indiana</option>
<option value="IA"> Iowa</option>
<option value="KS"> Kansas</option>
<option value="KY"> Kentucky</option>
<option value="LA"> Louisiana</option>
<option value="ME"> Maine</option>
<option value="MD"> Maryland</option>
<option value="MA"> Massachusetts</option>
<option value="MI"> Michigan</option>
<option value="MN"> Minnesota</option>
<option value="MS"> Mississippi</option>
<option value="MO"> Missouri</option>
<option value="MT"> Montana</option>
<option value="NE"> Nebraska</option>
<option value="NV"> Nevada</option>
<option value="NH"> New Hampshire</option>
<option value="NJ"> New Jersey</option>
<option value="NM"> New Mexico</option>
<option value="NY"> New York</option>
<option value="NC"> North Carolina</option>
<option value="ND"> North Dakota</option>
<option value="OH"> Ohio</option>
<option value="OK"> Oklahoma</option>
<option value="OR"> Oregon</option>
<option value="PA"> Pennsylvania</option>
<option value="RI"> Rhode Island</option>
<option value="SC"> South Carolina</option>
<option value="SD"> South Dakota</option>
<option value="TN"> Tennessee</option>
<option value="TX"> Texas</option>
<option value="UT"> Utah</option>
<option value="VT"> Vermont</option>
<option value="VA"> Virginia</option>
<option value="WA"> Washington</option>
<option value="WV"> West Virginia</option>
<option value="WI"> Wisconsin</option>
<option value="WY"> Wyoming</option>
</select><br><br>
<select multiple name="zipNames" style="width:100%; height:400px"></select>
</form>
</body>
</html>
但是我不知道要加什么FILE才能够完成整个连接,就是说那些STATE的资料应该怎样写,还有FILE NAME 是什么...
有人可以把这里用到的FILE都写出来吗? 然后我就可以知道怎样改成我要的东西了..
谢谢! |
|
|
|
|
|
|
|
楼主 |
发表于 1-8-2005 12:41 AM
|
显示全部楼层
大家应该明白我问什么吧? 我输入那些CODE,得到的只是空壳,没有资料的,我想知道那些资料应该储存在那里,用什么FILE NAME(用这个STATE的来做例子)...
那么我就可以知道那一个FILE代表什么,然后我就可以改成我要的资料...
谢谢!! |
|
|
|
|
|
|
|
发表于 1-8-2005 08:53 PM
|
显示全部楼层
你可以用 js 来 onchange refresh/redirect 去
_SERVER["PHP_SELF"] 加上 get (?var=value)
再从 database 去读出需要的资料 |
|
|
|
|
|
|
|
楼主 |
发表于 2-8-2005 12:27 AM
|
显示全部楼层
抱歉!我不明白你说什么...........新手!! |
|
|
|
|
|
|
|
发表于 3-8-2005 12:34 AM
|
显示全部楼层
首先,用 javascript 来控制当 onchange 的时候,refresh 并读出需要的资料。 |
|
|
|
|
|
|
|
楼主 |
发表于 3-8-2005 01:07 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 3-8-2005 09:52 PM
|
显示全部楼层
<SELECT OnChange='ChangeMe(this.value)>
function ChangeRack( ID ) {
window.location.href = 'http://server.com/test.php?ID=' + ID;
}
而你的 test.php 就可以根据 $_GET['ID'] 来读取需要的资料了。 |
|
|
|
|
|
|
|
楼主 |
发表于 4-8-2005 02:06 PM
|
显示全部楼层
原帖由 flashang 于 3-8-2005 09:52 PM 发表
<SELECT OnChange='ChangeMe(this.value)>
function ChangeRack( ID ) {
window.location.href = 'http://server.com/test.php?ID=' + ID;
}
而你的 test.php 就可以根据 $_GET['ID'] 来读取需要 ...
我还是不明白咯....我是新手来的.... |
|
|
|
|
|
|
|
发表于 4-8-2005 11:01 PM
|
显示全部楼层
[php]
$data1 = mysql_query( "SELECT * FROM table WHERE ID = '". $_GET['ID'] ."';");
$dset = mysql_fetch_assoc( $data1 );
[/php]
你需要先熟悉 javascript, php 及 get, post
然后就明白我说什么了。 |
|
|
|
|
|
|
|
楼主 |
发表于 5-8-2005 12:16 AM
|
显示全部楼层
java script 会少少, PHP 完全没有学过...看来还是不要做这个了... |
|
|
|
|
|
|
|
发表于 5-8-2005 12:41 AM
|
显示全部楼层
你可以去找一些 PHP+MYSQL 的 TUTORIAL
那么就容易明白了。 |
|
|
|
|
|
|
|
楼主 |
发表于 5-8-2005 10:41 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 9-8-2005 12:25 AM
|
显示全部楼层
谢谢!!!
我最近也是做这assignment
要用到MySQL, PHP, xhtml, 等等。
谢谢分享。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|