English 中文(简体)
Jquery: 点击下载列表时, 从一页切换到另一页
原标题:Jquery: To switch from one page to another on drop-down list click
  • 时间:2012-05-24 14:06:32
  •  标签:
  • jquery
  • html

I have one drop down list in my page, which contains two options. What i want is, when user select second value in drop down list, another page should load. that means how to switch page on clicking on of the drop down box values. for help i am putting my html code of drop down list.

        <select id = "viewList" class="fl width160">
            <option>Target</option>
            <option>Source</option>
        </select>

现在当用户点击源选项时, 其它js 页面应该打开。 以及我应该如何在. js 文件( Jquery) 中为此写入编码 。

最佳回答

你看,你需要 改变你的 html代码像这样

 <select id = "viewList" class="fl width160">
        <option value ="Target">Target</option>
        <option value ="Source">Source</option>
    </select>

$("#viewList").change(function() {
        if( $("#viewList").val == Target )
    {
        _loadTargetList();
    }
    else
    {
        _loadSourceList();
    }   
});

Here _loadTargetList and _loadSourceList both are the functions which will provide the location to load their html file or js files. Here is an example how to load html or js file If you want to call js first then html through js then go for this one

codeLoadingMgr.loadInclude( path +  /Target.js , function() {
codeLoadingMgr.getHTML(path +  /Target.html , function(html) {
});
});
Other wise you can direct load the html also.

希望这能帮上忙

问题回答

这是代码:

  <select id ="viewList" class="fl width160">
      <option value="" selected>Please select</option>
      <option value="http://www.google.com">Google</option>
      <option value="http://www.yahoo.com">Yahoo</option>
  </select>
<script type="text/javascript">
$(function(){$( #viewList ).bind( change , function(){if($(this).val()) window.location=$(this).val();});});
</script>​

“http://jsfiddle.net/7DxJC/8” rel=“no follow” > this jsfidle 。请注意,它可能不会在 Jsfidle 工作,因为它在一框架中运行代码。 您可以测试它 < a href=> http://fiddle.jshell.net/7DxJC/8show/" rel=“no follow” >这里

$("#viewList").change(function() {
   if ($(this).find( :selected ).text() ==  Source )
      window.location =  urltogoto ;
});

@PenchoIlchev的解决方案是有效的, 但如果您不想使用绑定方法, you可以尝试:

 <select id = "viewList" class="fl width160" onchange="change();">
        <option>Target</option>
        <option>Source</option>
    </select>​

function change(){
    url = $("#viewList option:selected").html();
    location.href = url;
}​

http://jsfiddle.net/FKJFC/" rel="nown" >http://jsfiddle.net/FKJFC/





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签