0

我的页面上有多个文本框,它们的 ID 以“Text”开头,后跟一个随机字符串,例如“Textc0816e05-d7c0-4acc-b233-bef152781cac”,当用户单击它时,如何选择文本框的值?

4

2 回答 2

1

您可以使用以下代码获取单击的文本框值

$('input[type=text][id^=Text]').on('click',function(){
     var value = $(this).val();

     //do what ever you want with the values
});

您可以查看Attributes start with selector文档。

于 2012-05-19T10:14:43.300 回答
1
$('input[type=text][id^=Text]').on('click', function() {
   console.log(this.value);
});
于 2012-05-19T10:14:53.153 回答