点击按钮从附近的输入中获取价值? [英] Click button to get value from nearby input?
本文介绍了点击按钮从附近的输入中获取价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在HTML中输入了一个按钮后,我想使用该按钮从该输入中检索值并执行操作。我遇到的问题是我的jQuery没有找到那个值。
HTML:
< DIV>
< input class =an-inputtype =text>< / input>
< button class =ui-state-default inputButton an-button> GO< / button>
< / div>
JS:
$('。an-button')。click(function(){
var inputValue = $('。an-button')。prev('。an-input')。find ('input')。val();
window.open('http://a810-bisweb.nyc.gov/bisweb/JobsQueryByNumberServlet?passjobnumber='+inputValue+'&passdocnumber=&go10=+ GO +& requestid = 0');
});
解决方案最接近:
var inputValue = $('。an-button')。closest('div ').find(' 输入)VAL();
I have a button that comes after an input in the HTML, and I want to use that button to retrieve the value from that input and perform an action. The problem I'm facing is that my jQuery isn't finding that value.
The HTML:
<div>
<input class="an-input" type="text"></input>
<button class="ui-state-default inputButton an-button">GO</button>
</div>
The JS:
$('.an-button').click(function() {
var inputValue = $('.an-button').prev('.an-input').find('input').val();
window.open('http://a810-bisweb.nyc.gov/bisweb/JobsQueryByNumberServlet?passjobnumber='+inputValue+'&passdocnumber=&go10=+GO+&requestid=0');
});
解决方案
Travel up the DOM with closest
:
var inputValue = $('.an-button').closest('div').find('input').val();
这篇关于点击按钮从附近的输入中获取价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文