javascript 如何在jQuery中获取输入文本字段的点击事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23041355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get click event of input text field in jQuery?
提问by Prakash GPz
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.
你能告诉我如何在jQuery中获取输入文本字段的点击事件吗?我有一个输入文本字段,我需要显示警报的单击事件。
<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>
回答by Prakash GPz
$('#text-12').click(function(e) {
alert('clicked');
});
in general, for all text inputs, use input[type="text"]
instead of #text-12
selector.
一般来说,对于所有文本输入,使用input[type="text"]
代替#text-12
选择器。
回答by Shirishkumar Bari
You can use the code below
您可以使用下面的代码
$('#text-12').click(function(){ alert("hello")});
回答by AlieN
Another solution:
另一种解决方案:
$('#text-12').on('click',function(){alert("alert-title")});