Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

点击ur列表将下面li里的内容,传递给input表单?

<div>
    <ul id="UlLi" onclick="hello()">
        <li value="11a"><a href=""> 111a</a></li>
        <li value="22"><a href=""> 22a</a></li>
        <li value="333"><a href=""> 33a</a></li>
        <li value="44"><a href=""> 44a</a></li>
    </ul>
    <input id="xxx_x" value="" />
</div>
<script>
    function hello() {
        var ul=document.getElementById("UlLi").getElementsByTagName("li");
        for(var i=0;i<ul.length;i++){
            var cityid=ul[i].getAttribute("value");
        }
        var input = document.getElementById("xxx_x");
        input.value?= cityid;
    }
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)

你现在这样input中存在的是最后一个也就是44

你应该是给li绑定事件,然后在click事件中给input赋值


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...