[英]How find the numbers in input value and hide are numbers with jQuery
我有这样的输入:
<input type="submit" name="starts" value=" 1154 Update " class="btn-success">
我需要在“ Value
查找任何数字并隐藏此数字,如下所示:
<input type="submit" name="starts" value=" Update " class="btn-success">
谢谢你的帮助....
我需要找到“值”中的任何数字并将其隐藏
您可以使用setAttribute
var button = document.querySelector('input[type="submit"][name="starts"]');
var value = button.getAttribute( "value" );
button.setAttribute( "value", value.replace(/\d+/g, "") ); //use trim if required
演示版
var button = document.querySelector('input[type="submit"][name="starts"]'); var value = button.getAttribute("value"); button.setAttribute("value", value.replace(/\\d+/g, "")); //use trim if required
<input type="submit" name="starts" value=" 1154 Update " class="btn-success">
您可以执行以下操作来替换数字。
我已经应用了Keyup和Change事件。
$("#inputRegex").change(function() { $(this).val($(this).val().replace(/\\d+/g, '')) }); $("#inputRegex").keyup(function() { $(this).val($(this).val().replace(/\\d+/g, '')) });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="inputRegex" />
如果要隐藏这些数字,请单击“提交”按钮:
$(":submit").click(function() {
string value = $(this).val().toString();
value = $.trim(value.replace(/\d+/g, ""));
$(this).val(value);
});
如果要在加载时隐藏:
$( document ).ready(function() {
$(":submit").each(function() {
string value = $(this).val().toString();
value = $.trim(value.replace(/\d+/g, ""));
$(this).val(value);
});
})
这将删除所有输入类型Submit的值中的所有数字。 这是小提琴
HTML部分:
<input type="submit" name="starts" value=" 1154 Update " class="btn-success">
<input type="submit" name="starts" value=" 1155 Update " class="btn-success">
<input type="submit" name="starts" value=" 1156 Update " class="btn-success">
和jQuery部分:
$('input[type="submit"]').val($('input[type="submit"]').val().replace(/\d+/g, "").trim());
这个小提琴可能会帮助您。
如果要隐藏它。 您可以将任何数据属性设置为“提交”按钮
<input type="submit" name="starts" data-id ="1154" value="Update " class="btn-success">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.