最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get click event of input text field in jQuery? - Stack Overflow

programmeradmin4浏览0评论

Can you please tell me how to get the click event of an input text field in jQuery? I have one input text field I need click event of that showing alert.

<div data-role="fieldcontain">
    <label for="text-12" class="name_label_field">Name<span class="custom-label">*</span> :</label><span class="mandatory_label fright custom-label">*<span class="test_1">Maximum Limit 260</span></span>
    <input name="text-12" id="text-12" value="" type="text" class="documentName_h name_input_box" autocorrect="off" maxlength="240" onkeypress="validateNote(event)">
</div>

Can you please tell me how to get the click event of an input text field in jQuery? I have one input text field I need click event of that showing alert.

<div data-role="fieldcontain">
    <label for="text-12" class="name_label_field">Name<span class="custom-label">*</span> :</label><span class="mandatory_label fright custom-label">*<span class="test_1">Maximum Limit 260</span></span>
    <input name="text-12" id="text-12" value="" type="text" class="documentName_h name_input_box" autocorrect="off" maxlength="240" onkeypress="validateNote(event)">
</div>
Share Improve this question edited Apr 13, 2014 at 17:31 Jason Aller 3,65228 gold badges41 silver badges39 bronze badges asked Apr 13, 2014 at 10:02 user2484319user2484319 1
  • jsfiddle/p9TC4 – caramba Commented Apr 13, 2014 at 10:04
Add a ment  | 

3 Answers 3

Reset to default 2
 $('#text-12').click(function(e) {
     alert('clicked');
 });

in general, for all text inputs, use input[type="text"] instead of #text-12 selector.

Another solution:

$('#text-12').on('click',function(){alert("alert-title")});

You can use the code below

$('#text-12').click(function(){ alert("hello")});
发布评论

评论列表(0)

  1. 暂无评论