1

I am having a problem with my html document. I am trying to find the value of the iput box below but it wont work. It has that the value is blank. I am running to document as a file in my computer, not on the web, if that makes a difference. This is my html code:

<p class='textcenter'>What would you like to scan</p><input id='scanbox1' type='text' name='scanboxtype'>

And this is my jquery:

var a;
a = $('input[name=scanboxtype]').val();
alert('a is '+a)

What ever i type in, the alert pops up as 'a is'. Thanks for the help.

4

2 回答 2

1

您尚未在提交或更改或任何其他事件时触发警报。

所以你看不到带有值的警报消息

结果总是“a is”

例子:

使用.change()

$('input[name=scanboxtype]').change(function(){
    alert('a is '+ this.value); // or $(this).val()
});

使用.keyup()

$('input[name=scanboxtype1]').keyup(function(){
    alert('a is '+ this.value); // or $(this).val()
});

参考现场演示

于 2013-06-30T20:53:00.073 回答
0

例如,当按下键时,您的代码可能正在运行,但输入元素中还没有值?例如在“keydown”之类的?

于 2013-06-30T20:53:09.453 回答