我的链接:
<a href="<?php echo $r['price']; ?>" id="buyorderprice" value=""><?php echo $r['price']; ?></a>
和我的不工作的jquery:
$('a[href="buyorderprice"]').click(function(){
$('#sellprice').val($('#buyorderprice').attr('href'))
});
价格值只是一个有效的数字。另外,我不希望在单击按钮时重新加载页面,只需更新销售价格输入即可:
<input type="text" class="form-control" id="sellprice" name="sellprice" value="<?php echo
$coinTicker->price($coin2[1] , 'sell'); ?>">
硬币是随机数的默认值
最佳答案
使用 javascript/Vanilla JS,你可以这样实现:
var a = document.getElementById('buyorderprice');
a.addEventListener('click',setValueNow);
function setValueNow(e) {
e.preventDefault();
var b = document.getElementById('sellprice').value = document.getElementById('buyorderprice').getAttribute('href');
}
<强> Here's a DEMO
关于javascript - 使用 href Jquery 的值更新输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27435042/