首页 新闻 会员 周边

一个久未解决的老问题了,涉及脚本和aspx页面

0
悬赏园豆:10 [已关闭问题]

不知我能否表达清楚。一个search.aspx页面用来做搜索,别的页面提交get到search.aspx,search.aspx页面还可以允许浏览者再次搜索,问题是没有源码, 不能写在服务器端,只能通过脚本解决,我是这样写的:

<script>

function noFormGoSearch()
{
 var t = document.getElementById("SearchItem").value;
    var v = trim(document.getElementById("Keyword").value);
 if(v.length > 100){
  alert("您输入的关键字过长!");
  return false;
 }
 if(v == ""  || v.substring(0,3) =="请输入") {
  alert("请输入关键字!");
  return false;
 }
 var url = "/search.aspx?t="+t+"&q="+encodeURI(v);
 window.open(url);
}

</script>

<input tabindex="1" type="text" id="Keyword" value="" onfocus="this.value=''" style="width: 200px" />
                <select id="SearchItem" name="SearchItem">
                    <option value="seller">供应信息</option>
                    <option value="buyer">求购信息</option>
                </select>
                <input tabindex="2" type="submit" class="searchbtn" value="搜  索" onclick="return noFormGoSearch()" />

用起来倒是可以,问题是window.open让我很不爽,而且浏览者要打开一个新的窗口,用户体验也不好,怎么样做才能只在本页进行搜索呢?

问题补充: 用form action也没用,只是刷了下页面,并未提交新的请求。看下面部分源文件: <script type="text/javascript"> function trim(value){return value.replace(/(^\s*)|(\s*$)/g, "");} function noFormGoSearch(){ var t = document.getElementById("SearchItem").value; var v = trim(document.getElementById("Keyword").value); if(v.length > 100){ alert("您输入的关键字过长!"); return false; } if(v == "" || v.substring(0,3) =="请输入") { alert("请输入关键字!"); return false; } var url = "/search.aspx?t="+t+"&q="+encodeURI(v); alert(url); document.getElementById("form1").action=url;} </script> </head> <body> <form name="form1" method="post" action="search.aspx?t=news&amp;q=%u4e94%u82b1%u516b%u95e8" id="form1"> ....
红尘中迷茫的主页 红尘中迷茫 | 初学一级 | 园豆:60
提问于:2008-12-10 21:56
< >
分享
其他回答(3)
0

还真有点不太明白.

Astar | 园豆:40805 (高人七级) | 2008-12-10 23:35
0

你这个代码里并没有window.open啊?

你试着把你里面的window.open替换成location.href,看是不是你想要的效果?

丁学 | 园豆:18730 (专家六级) | 2008-12-11 07:47
0

是啊 location.href在本身页面跳转不就可以了

码尔代夫iimax | 园豆:3138 (老鸟四级) | 2008-12-11 09:40
0

用form action="指定页面"

sl2008 | 园豆:407 (菜鸟二级) | 2008-12-11 11:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册