【问题标题】:Create button that inserts typed value from adjacent input into URL?创建将来自相邻输入的键入值插入 URL 的按钮?
【发布时间】:2013-07-09 16:54:29
【问题描述】:

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

假设我在文本字段中输入 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>

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

【问题讨论】:

  • window.open('?passjobnumber=' + this.value);?
  • 请提供问题的 HTML 代码
  • @Hast:就像你回复的那样添加它。

标签: php jquery forms button input


【解决方案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');
    })
});

【讨论】:

    【解决方案2】:

    你应该可以这样做:

    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');
    });
    

    【讨论】:

    • 感谢您的回答,我选择了 Hast 对 jQuery 的回答。
    猜你喜欢
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    • 2013-04-19
    • 2011-06-30
    相关资源
    最近更新 更多