Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击按钮从附近的输入获取值?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 单击按钮从附近的输入获取值?

Javascript 单击按钮从附近的输入获取值?,javascript,jquery,html,Javascript,Jquery,Html,我有一个在HTML中输入之后的按钮,我想使用该按钮从该输入中检索值并执行操作。我面临的问题是,我的jQuery没有找到那个值 HTML: <div> <input class="an-input" type="text"></input> <button class="ui-state-default inputButton an-button">GO</button> </div> 使用最近的沿DOM向上

我有一个在HTML中输入之后的按钮,我想使用该按钮从该输入中检索值并执行操作。我面临的问题是,我的jQuery没有找到那个值

HTML:

<div>
    <input class="an-input" type="text"></input>
    <button class="ui-state-default inputButton an-button">GO</button>
</div>

使用
最近的
沿DOM向上移动:

 var inputValue = $('.an-button').closest('div').find('input').val();

使用
最近的
沿DOM向上移动:

 var inputValue = $('.an-button').closest('div').find('input').val();

尝试删除
.find('input')
,因为
.prev(.an input”)
应该返回
input
元素。还要注意,
标记是自动关闭的

$(“.an按钮”)。单击(函数(){
var inputValue=$(this.prev(“.an input”).val();
console.log(inputValue)
//打开窗户http://a810-bisweb.nyc.gov/bisweb/JobsQueryByNumberServlet?passjobnumber=“+inputValue+”&passdocnumber=&go10=+GO+&requestid=0”);
});
尝试删除
.find('input')
,因为
.prev(.an input”)
应该返回
input
元素。还要注意,
标记是自动关闭的

$(“.an按钮”)。单击(函数(){
var inputValue=$(this.prev(“.an input”).val();
console.log(inputValue)
//打开窗户http://a810-bisweb.nyc.gov/bisweb/JobsQueryByNumberServlet?passjobnumber=“+inputValue+”&passdocnumber=&go10=+GO+&requestid=0”);
});

要以兄弟姐妹为目标,它必须是类似的类型

请尝试以下方法:

$('.an-button').click(function() {
    var inputValue = $('.an-button').parent().find('.an-input').val();
    window.open('http://a810-bisweb.nyc.gov/bisweb/JobsQueryByNumberServlet?passjobnumber='+inputValue+'&passdocnumber=&go10=+GO+&requestid=0');
});

要以兄弟姐妹为目标,它必须是类似的类型

请尝试以下方法:

$('.an-button').click(function() {
    var inputValue = $('.an-button').parent().find('.an-input').val();
    window.open('http://a810-bisweb.nyc.gov/bisweb/JobsQueryByNumberServlet?passjobnumber='+inputValue+'&passdocnumber=&go10=+GO+&requestid=0');
});

输入元素没有结束标记

更多信息


正确的是输入元素没有结束标记

更多信息


正确的做法是

你应该从链接中添加核心概念和内容,因为链接可能会随着时间的推移而过时。你应该从链接中添加核心概念和内容,因为链接可能会随着时间的推移而过时。