开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜