通过inputfield更新按钮文本
Update button text through inputfield
是否有一种方法可以动态地更新按钮文本,而一些值正在输入一个输入字段
<input class="paymentinput w-input" type="tel" placeholder="0" id="amount-field">
<button id="rzp-button1" class="paynowbutton w-button">Pay Now</button>
我想用id="amount-field"输入字段中输入的值更新按钮文本"Pay Now"
我知道我应该为此使用onKeyUp,但我对如何编写此代码有点无能为力。
这是你想要的吗?
$('.myName').keyup(function(){
if ($(this).val()==""){
$('button').text("Pay Now")
}else{
$('button').text($(this).val());
}
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="myName">
<button>sample</button>
您是对的,您可以使用keyup
事件来实现这一点。
document.getElementById('amount-field').addEventListener('keyup', function() {
document.getElementById('rzp-button1').innerText = 'Pay Now ' + this.value;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="paymentinput w-input" type="tel" placeholder="0" id="amount-field">
<button id="rzp-button1" class="paynowbutton w-button">Pay Now</button>
你已经用jQuery标记了这个问题,下面是如何使用jQuery实现它
$(function() {
$('#amount-field').keyup(function() {
$('#rzp-button1').text('Pay Now ' + this.value);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="paymentinput w-input" type="tel" placeholder="0" id="amount-field">
<button id="rzp-button1" class="paynowbutton w-button">Pay Now</button>
在这里,
$("#amount-field").keyup(function(){
var value = $(this).val();
$("#rzp-button1").text(value);
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#amount-field").keyup(function(){
$('#rzp-button1').text($(this).val());
});
});
</script>
</head>
<body>
<input class="paymentinput w-input" type="tel" placeholder="0" id="amount-field">
<button id="rzp-button1" class="paynowbutton w-button">Pay Now</button>
</body>
</html>
你在找这个吗?
如果你想附加文本,那么最好使用另一个内联标签像。
$('#amount-field').keyup(function() {
var keyed = $(this).val();
$("#rzp-button1 span").text("- "+keyed); // you can remove "-"
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="paymentinput w-input" type="tel" placeholder="0" id="amount-field">
<button id="rzp-button1" class="paynowbutton w-button">Pay Now <span></span></button>
相关文章:
- 将文本框链接到由按钮运行的javascript公式
- JS中的按钮和文本输入
- 将文本框中的值用于按钮窗体操作上的变量
- 使用加号按钮添加多个文本框,并通过PHP提交
- 输入文本框为空时的阻止按钮asp.网络表单
- 如何通过单击html按钮获得h1的文本值
- 我想重定向点击,然后更改按钮文本,我该怎么做
- html代码需要可点击的文本按钮
- 如何在单击按钮时显示文本(按钮被<span></span>标记包围)
- 用于 asp:label 的 Javascript 更多/更少文本按钮
- 如何使用jquery消除html/文本按钮内容
- 输入文件-更改数据按钮文本的文本按钮
- “编辑文本”按钮不起作用
- “更改范围文本”按钮
- 垂直对齐文本与短长文本按钮
- 为什么文本/按钮跳转页面加载(Chrome)
- 如何在移动操作系统(android,ios)中使用Javascript触发复制文本按钮
- 为文本按钮分配Jquery列表值
- Jquery改变文本按钮显示更多/显示更少
- Javascript如何制作复制此文本按钮