[英]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.