jQuery, get value when user inserts text
when user insert text input i wish get, and insert in link. How that make with jQuery?
My try (very bad :( ):
<script type="text/javascript">
$(document).ready(function() {
var values = $('#user').val();
});
</script>
<body>
<div id = "ta开发者_如何学Pythonble">
<input type = "text" id = "user" value = "my_name" />
</div>
<a href = "http://www.link.com/?name=<script>values</script>">link</a>
$(function() {
// listen for the change event on the textbox
$('#user').change(function() {
// when the user changes the value of the textbox
// get the new value
var name = this.value;
// and put this value in the link
$('a#mylink').attr('href', 'http://www.link.com/?name=' + name);
});
});
where the anchor is defined like so:
<a href="http://www.link.com/?name=my_name" id="mylink">link</a>
You may see this in action here.
精彩评论