嗨我想从文本框中获取值并附加到超链接作为id。这是我的代码,但我无法获得文本框的值。
<li><a class="ajax-link" href="ajax/legal_notice.php?id=+ document.getElementById('cust_id').value">Hypelink name</a></li>
<div class="col-sm-6">
Customer Id
</div>
<div class="col-sm-6">
<input type="text" name="cust_id" id="cust_id" class="form-control" >
</div>
请指导我如何从文本框中获取价值。
答案 0 :(得分:0)
试试这个
<html>
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
alert("hello");
function resetLink(ele)
{
var href="ajax/legal_notice.php?id="+$(ele).val();
$(".ajax-link").attr("href",""+href);
}
</script>
</head>
<body>
<li><a class="ajax-link" href="ajax/legal_notice.php?id=+ document.getElementById('cust_id').value">Hypelink name</a></li>
<div class="col-sm-6">
Customer Id
</div>
<div class="col-sm-6">
<input type="text" name="cust_id" id="cust_id" onchange="resetLink(this);" class="form-control" >
</div>
</body>
答案 1 :(得分:0)
见下文:
<script>
function append() {
var link = document.getElementById('link');
var text = document.getElementById('cust_id');
link.href = "ajax/legal_notice.php?id=" + text.value;
link.text = text.value;
}
</script>
<a id="link" href="ajax/legal_notice.php?id=+ document.getElementById('cust_id').value">Hypelink name</a>
<div class="col-sm-6">
Customer Id
</div>
<div class="col-sm-6">
<input type="text" name="cust_id" id="cust_id" class="form-control" onchange="append();">
</div>