2013-05-10 29 views
0

我有两个输入框和按钮。如果我在第一个文本框中输入url并在第二个文本框中输入搜索文本。现在我需要结果在iframe中。我尝试过,但画面会是空的....搜索到一个网站和结果显示在iframe使用javascript

下面的代码....

<!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"> 
<?php 
header('X-Frame-Options: GOFORIT'); 
?> 
<head> 
<script type="text/javascript"> 


function Gsitesearch(curobj) 
{ 
var domainroot=document.frm.domain.value; 
var date=document.frm.opt.value; 
curobj.q.value="site:"+domainroot+" "+curobj.qfront.value+" "+curobj.opt.value 
} 
</script> 
</head> 
<body> 
<form action="http://www.google.com/search" id="frm" name="frm" target="myiframe" method="get" onsubmit="Gsitesearch(this)"> 
<center> 
<h2>Search Tool Kit:</h2><br /> 
<table cellpadding="10" cellspacing="10"> 
<tr><td><input name="q" type="hidden" /></td></tr> 
<tr><td><b>Domain Name:</b></td><td><input id="domain" type="text" style="width: 180px" /></td></tr> 
<tr><td><b>Search Word</b></td><td><input name="qfront" type="text" style="width: 180px" /></td><td><select name="opt"><option>1</option><option>2</option></select></td></tr> 
<tr><td colspan="2" align="right"><input type="submit" id="search" value="Search" /></td></tr> 
</table> 
</form> 
<iframe name="myiframe" style="width:550px; height:100px;"></iframe> 


</body> 
</html> 

任何机构帮助我....

+1

定义“不起作用”。它有什么作用?当你调试它时,你期望它们是运行时值吗?另外,你已经提到过几次jQuery,但是你并没有在这里使用jQuery。还有其他代码吗? – David 2013-05-10 11:39:14

+0

雅,其实搜索结果不加载iframe ...我需要,如果代码将在jquery ...多数民众赞成在它.. – 2013-05-10 11:45:11

+0

注意:搜索结果应显示在iframe中, – 2013-05-10 11:46:30

回答

0

这里,我们去:

的HTML +的Javascript:(的index.php)

<form id="myForm" > 
    <input type="text" name="first" value="22" /> 
    <input type="text" name="second" value="" /> 
    <input type="button" value="See result on iframe" onclick="iframeResults()" /> 
</form> 
<br/> 
<iframe src="#" name="results"></iframe> 

<script type="text/javascript"> 
function iframeResults(){ 
    var 
     form = document.getElementById("myForm"), 
     first = form.elements.namedItem("first").value, 
     second = form.elements.namedItem("second").value; 
    if(first.length && second.length){ 
     window.results.location.href='results.php?first=' + first + '&second=' + second; 
    }else{ 
     alert('Type some text on the two inputs before ;)'); 
    } 
} 
</script> 

...,最后...

的PHP:(results.php)

<?php 
if(isset($_GET["first"]) && $_GET["first"] != "" && isset($_GET["second"]) && $_GET["second"] != ""){ 
    echo 'Received:<br/> 
    First: '.$first.';<br/> 
    Second: '.$second; 
}else{ 
    echo 'Error! Type some text on the two inputs before. ;)'; 
} 
?> 

字体:

编辑:能源部s不适用于交叉框架;)

相关问题