0

我有一个包含多个输入的表单,每个输入都有自己的按钮。我希望每个按钮将相邻输入的键入值插入到新的浏览器选项卡中,并在单击按钮时打开该地址。

假设我在文本字段中输入 121680573,当我单击字段旁边的按钮时,应该在新选项卡中打开此地址:

a810-bisweb.nyc.gov/bisweb/JobsQueryByNumberServlet?passjobnumber= 121680573 &passdocnumber=&go10=+GO+&requestid=0

键入的值必须插入到 = 符号之后的特定位置。

到目前为止,这是我完成这项任务的唯一代码(为了这个示例,我创建了一个警报,因为我不知道如何完成文本的插入)。#bis 代表按钮:

$(document).ready() {
    var bis_button = $('.bis_button');
        bis_button.click(function() {
            alert(bis_button.val());
        });
});

输入和按钮在 WordPress 页面中是这样排列的。每个输入都由创建页面的 WordPress 插件分配一个 ID:

<div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]">
    <label  class="frm_primary_label">[field_name]
        <span class="frm_required">[required_label]</span>
    </label>
    [input]
    [if description]<div class="frm_description">[description]</div>[/if description]
    [if error]<div class="frm_error">[error]</div>[/if error]
<div class="bis_button">View in BIS</div>
</div>

我附上了一张图片,显示了字段及其各自的按钮。:

按钮和字段

4

2 回答 2

1
$(document).ready(function() {
    $(".bis_button").click(function() {
        var inputValue = $(this).parent('.frm_form_field').find('input').val();

        window.open('a810-bisweb.nyc.gov/bisweb/JobsQueryByNumberServlet?passjobnumber='+inputValue+'&passdocnumber=&go10=+GO+&requestid=0');
    })
});
于 2013-07-09T17:05:40.623 回答
0

你应该能够做到这一点:

bis.click(function() {
    var prefix = "a810-bisweb.nyc.gov/bisweb/JobsQueryByNumberServlet?passjobnumber=";
    var suffix = "&passdocnumber=&go10=+GO+&requestid=0"
    var url = prefix + $(this).siblings("input[type='text']").val() + suffix;

    window.open(url,'_blank');
});
于 2013-07-09T17:03:38.513 回答