javascript - thinkphp中如何给a标签传递的参数为文本框的输入值?

WBOY
Release: 2016-06-06 20:14:22
Original
1839 people have browsed it

javascript - thinkphp中如何给a标签传递的参数为文本框的输入值?

如图,怎么令a中的参数是上面文本框的输入值。
我之前的写法是
{:U('地址',array('seaname'=>''+document.getElementById('search_key').value+''))}
但是不行。
第二次是在js中写,
var a=$('#search_key').val();
链接ID.href="地址?seaname="+a;也不行

回复内容:

javascript - thinkphp中如何给a标签传递的参数为文本框的输入值?

如图,怎么令a中的参数是上面文本框的输入值。
我之前的写法是
{:U('地址',array('seaname'=>''+document.getElementById('search_key').value+''))}
但是不行。
第二次是在js中写,
var a=$('#search_key').val();
链接ID.href="地址?seaname="+a;也不行

<code>


    <meta charset="utf-8">
    <title>dfdf</title>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#a").bind("click",function(){
                var v=$("#i").val();
                var link="https://www.baidu.com/s?wd="+v;
                $("#a").attr("href",link);
            })
        });
    </script>


<input type="text" id="i">
<a href="" id="a">搜索</a>

</code>
Copy after login

这是个demo,把内容替换掉试试

$("search_key").bind('keyup mouseup', function () {

<code>在这里改变你的 href地址,试试,没有测试过,自己尝试一下吧           </code>
Copy after login

});

<code class="javascript">$(function() {
    $('#search_stuff').on('click', function(e) {
        var url = $('#search_key').val();
        $(this).attr('href', url);
    })
})</code>
Copy after login

给你提供一种思路:
1 声明一个存储变量a,监听input的keyup事件
2 在监听事件中实时获取input的值,并把值传递给a

简单事咧:

<code><input id="inp" type="text" placeholder="默认值">
  <p id="txt">我是实时改变的值。。。。</p>

  <script>
  var obj = document.getElementById('inp');
  obj.addEventListener('keyup', function(e) {
    // console.log(obj.value);
    document.getElementById('txt').innerHTML = obj.value;
  }, false);
  </script></code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!