将文本输入转换为数字输入
目前我有一堆文本输入,我无法更改 HTML(因为它是预先生成的),但我想将它们从 type="text" 转换为 type="number",是否有一些我可以使用 jQuery 或 JavaScript 来实现这一目标吗?
这是一个针对移动设备的小型应用程序。
基本上我想转换
<input type="text" id="MyID" name="MyName">
为
<input type="number" id="MyID" name="MyName">
我正在尝试类似
<script>
function DoWhenReady() {
$('#MyID').attr('type', 'number');
}
$(document).ready(DoWhenReady);
</script>
在标题中的内容,但没有成功-建议?
Currently I have a bunch text inputs, which I can't change the HTML for (as it is pre-generated), but I want to convert them from type="text" to type="number", is there a bit of jQuery or JavaScript I can use to achieve this?
This is in a small application for mobile devices.
Basically I want to convert
<input type="text" id="MyID" name="MyName">
to
<input type="number" id="MyID" name="MyName">
I was trying something like
<script>
function DoWhenReady() {
$('#MyID').attr('type', 'number');
}
$(document).ready(DoWhenReady);
</script>
In the header, but without success - suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
$('#MyID').prop('type', 'number');
(属性
)Try
$('#MyID').prop('type', 'number');
(jQuery 1.6+ required forprop
)