我需要允许用户将数字字符输入到两个使用不同ID的文本框中。
$('#signup-phone-number').keyup( function() {
$(this).numeric();
});
上面的代码是我目前拥有的。现在我试图将其更改为:
$('#signup-phone-number', '#mobile-number').keyup( function() {
$(this).numeric();
});
上面的代码不起作用。我只需要使用ID。没有课程。
我该怎么做?
尝试使用类似
$('#signup-phone-number , #mobile-number').keyup( function() {
$(this).numeric();
});
甚至您都可以给他们一个UNIQUE class
并在该类上使用您想要的事件,例如
$('.common_class').keyup( function() {
$(this).numeric();
});
使用相同引号内的选择器:
$('#signup-phone-number, #mobile-number').keyup( function() {
$(this).numeric();
});
或者或者将类添加到这两个元素中,并使用它,因为这是一种更具语义的方法。
对于多个选择器,请使用'#signup-phone-number , #mobile-number'
而不是'#signup-phone-number' , '#mobile-number'
$('#signup-phone-number , #mobile-number').keyup( function() {
$(this).numeric();
});
<script>
$(function() {
$('#segement1,#segement2,#segement3').hide()
});
</script>
<div id="segement1"></div>
<div id="segement2"></div>
<div id="segement3"></div>