jQuery目标的空白atr-在脚本中的何处包含此内容? [英] jQuery target blank atr - where to include this in the script?

查看:85
本文介绍了jQuery目标的空白atr-在脚本中的何处包含此内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下jquery脚本,用于处理站点访问者在外部站点上搜索所输入的查询.

I have the following jquery script, which deals with a query site-visitors enter to search on external sites.

    $("#Sbutton"+i).click(function(){
        var my_id = $(this).attr('id').substr(8);
        //alert(my_id);
        SearchUrl = $('#Search'+my_id).val();
        SearchQuery = $('#String'+my_id).val();
        location = SearchUrl+SearchQuery;

当前,查询被加载到与输入查询相同的窗口中.我想以与"target:_blank"类似的方式进行操作.看来我必须使用类似".attr("target","_ blank")的代码,但是我似乎无法弄清楚.

Currently, the query is loaded in the same window as where the query is entered. I'd like to have this in a similar way as 'target:_blank'. It seems I have to use code something like ".attr("target","_blank")", but I can't seem to figure this out.

有人帮我吗?

提前谢谢!

推荐答案

这是您可以做的(或类似的事情):

Here's what you can do (or something like it):

<form class="searchForm" target="_blank">
   <input type="hidden" class="searchUrl" />
   <input type="text" class="searchQuery" />
   <input type="submit" />
</form>

然后是您的JS:

$(document).ready({
  $(".searchForm").bind("submit", function() {
    var SearchUrl = $(this).children(".searchUrl").val();
    var SearchQuery = $(this).children(".searchQuery").val();
    var location = SearchUrl + SearchQuery;
    $(this).attr("action",location);
    $(this).submit();
  });
});

基本思想是,您在父表单元素上创建一个处理程序,然后从该处理程序中查找适当的数据并创建位置字符串.然后,事件处理程序将表单的操作更改为新的位置字符串,然后提交表单.

The basic idea is, you create a handler on the parent form element, which then finds the appropriate data from within it and creates the location string. The event handler then changes the action of the form to the new location string, and submits the form.

这篇关于jQuery目标的空白atr-在脚本中的何处包含此内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆