我有这个按钮,应该转到值中的页面,但是当我有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”不起作用?
答案 0 :(得分:0)
无论样式如何,这都不起作用,因为select
只有一个option
默认选中。当您再次尝试选择它时,select
中的值不会发生变化,因此不会触发onchange
事件。
使这项工作的两种方法:
option
添加到select
(<option value=''>---</option>
)onchange
更改为onblur
个事件。 我更喜欢第一种选择,因为它更加明智。另外,考虑调用函数而不是内联Javascript代码。
<select onchange='javascript:getrow(this.value);'>
<script>
function getrow(no) {
if (no!='')
location.href = 'table.php?row='+no;
}
</script>