简体   繁体   English

HTML Select样式

[英]HTML Select styled

I have this button, that should go to the page in the value, but it don't when i have the css, without it works, but looks bad: 我有这个按钮,应该在值中转到页面,但是当我有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>

And this CSS: 而这个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;
}

Why don't the "Onchange" not work? 为什么“ Onchange”不起作用?

This will not work irrespective of the style, because the select has only one option which is selected by default. 这与样式无关,因为select仅具有一个默认选中的option When you try selecting it again, there is no change of value in the select and so the onchange event is not fired. 当您再次尝试选择它时, select的值没有变化,因此不会触发onchange事件。

Two ways to make this work: 有两种方法可以使这项工作:

  1. Adding a dummy option to the select ( <option value=''>---</option> ) 将虚拟option添加到select<option value=''>---</option>
  2. Changing onchange to onblur event. onchange更改为onblur事件。

I would prefer the first option because it is more sensible out of the two. 我更喜欢第一种选择,因为这两种选择之间比较明智。 Also, consider calling a function rather than having inline Javascript code. 另外,考虑调用一个函数,而不要使用内联Javascript代码。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM