HTML选择样式

时间:2012-10-26 21:56:55

标签: html css select styles onchange

我有这个按钮,应该转到值中的页面,但是当我有css时没有它,但没有它可行,但看起来很糟糕:

<form action="table.php" name="rows" method="POST">
    <select class="styledselect_pages" onchange="window.location.href = this.options[this.selectedIndex].value;">
    <option value="table.php?row=100">100</option>
    </select>
</form>

这个CSS:

.styledselect_pages {
    background              :url(../images/table/select_number_rows.gif) left no-repeat;
    border                  :none;
    border-left             :none;
    color                   :#393939;
    cursor                  :pointer;
    display                 :block;
    font-family             :Arial;
    font-size               :12px;
    height                  :20px;
    line-height             :16px;
    margin                  :0px 0px 0px 0px;
    padding                 :4px 0 0 6px;
    text-align              :left;
    width                   :130px;
}

为什么“Onchange”不起作用?

1 个答案:

答案 0 :(得分:0)

无论样式如何,这都不起作用,因为select只有一个option默认选中。当您再次尝试选择它时,select中的值不会发生变化,因此不会触发onchange事件。

使这项工作的两种方法:

  1. 将假名option添加到select<option value=''>---</option>
  2. onchange更改为onblur个事件。
  3. 我更喜欢第一种选择,因为它更加明智。另外,考虑调用函数而不是内联Javascript代码。

    <select onchange='javascript:getrow(this.value);'>

    <script>
    function getrow(no) {
        if (no!='')
            location.href = 'table.php?row='+no;
    }
    </script>
    
相关问题