javascript - get text area and text field data - jquery - Stack Overflow

I have 2 text areas in my page as;<input type="text" id="a1"><textarea i

I have 2 text areas in my page as;

<input type="text" id="a1"/>
<textarea id="b2"></textarea>
<a id="button">button</a>

When user click the button link, I want to alert the data entered in a1 and b2.

How can I do this?? Here is there demo

Thanks in advance...:)

blasteralfred

I have 2 text areas in my page as;

<input type="text" id="a1"/>
<textarea id="b2"></textarea>
<a id="button">button</a>

When user click the button link, I want to alert the data entered in a1 and b2.

How can I do this?? Here is there demo

Thanks in advance...:)

blasteralfred

Share Improve this question asked Apr 12, 2011 at 6:41 AlfredAlfred 21.4k63 gold badges174 silver badges257 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5
  $(document).ready(function() {
    $('#button').click(function(e) {
      e.preventDefault();
      alert($('#a1').val());
      alert($('#b2').val());
    });
  });

dont use same id a1 for <a id="button">button</a> and <input type="text" id="a1"/>

and you can use jquery val() function to get value

alert($('#a1').val());
alert($('#b2').val());

Do like this :

window.alert($("#a1").val());
window.alert($("#a2").val());

Your code should appear likt this :

<input type="text" id="a1"/>
<textarea id="b2"></textarea>
<a id="button" onclick="window.alert($('#a1').val());window.alert($('#a2').val());return false;">button</a>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745629941a4637044.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信