【问题标题】:drop down instead of a href下拉而不是href
【发布时间】:2012-04-17 16:07:19
【问题描述】:

我想将此输入更改为下拉菜单。

<a href="#" onclick="$('#pb1').progressBar(5);">5</a> |
<a href="#" onclick="$('#pb1').progressBar(60);">60</a> |
<a href="#" onclick="$('#pb1').progressBar(100);">100</a>

下拉示例...(不起作用)

<form action="#" name="progress" onclick="$('#pb1').progressBar(10);">
   <select name="dropdown">
    <option name="radOne" value="$('#pb1').progressBar(5);" selected>5</option>
    <option name="radOne" value="$('#pb1').progressBar(60);">60</option>
    <option name="radOne" value="$('#pb1').progressBar(100);">100</option>
   </select>
</form> 

谁能帮我改变这个结构?

【问题讨论】:

    标签: javascript jquery html drop-down-menu href


    【解决方案1】:

    你应该这样做。

       <select name="dropdown" onchange="$('#pb1').progressBar(this.value);">
        <option name="radOne" value="5" selected>5</option>
        <option name="radOne" value="60">60</option>
        <option name="radOne" value="100">100</option>
       </select>
    

    即使像 show 一样,也不鼓励使用内联事件处理程序。更好的方法是

    document.getElementByid("selectboxid").onchange = function() {
        $('#pb1').progressBar(this.value);
    };
    

    但是,既然你已经在使用 jQuery

    $("#selectboxId").change(function() {
        $('#pb1').progressBar(this.value);
    });
    

    【讨论】:

    • 既然已经有了 jQuery,为什么还要使用普通的 DOM 方法?!
    • 因为他已经在使用它(至少我不知道另一个使用$('selector')的js框架)并且混合两个世界只是丑陋的。
    • @ThiefMaster,我不想浪费你的建议,所以更新了:)
    • @ThiefMaster:Mootools 也使用$('selector') :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 2023-03-27
    • 2018-09-07
    • 1970-01-01
    • 2016-06-18
    相关资源
    最近更新 更多