如下代码,利用td::after为select加了下拉图片,怎么才能点击蓝色区域触发select??
PS:一定要是select,因为插件就是select改不了
尝试过:
$('.select-ele').each(function () {
$(this).on('click', function (e) {
$(this).children('select').trigger('click');
})
});
<td class="select-ele">
<select>A</select>
</td>
<td class="select-ele">
<select>B</select>
</td>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
table tr td {
width: 105px;
height: 50px;
line-height: 50px;
position: relative;
}
table tr td select {
appearance: none;
-webkit-appearance: none;
width: 100%;
height: 50px;
padding-left: 15px;
}
table tr td.select-ele::after {
content: '﹀';
color: #ffffff;
font-size: 24px;
display: block;
width: 36px;
height: 50px;
line-height: 50px;
position: absolute;
top: 2px;
right: 0;
background: skyblue;
text-align: center;
}
</style>
</head>
<body>
<table>
<tbody>
<tr>
<td class="select-ele"><select name="city" id="city">
<option value="1">深圳</option>
<option value="2">广州</option>
<option value="3">杭州</option>
</select></td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
原文链接:纯CSS实现点击图片触发select下拉框使之展开
搞了半天事件,结果发现是样式的问题。
在你的
table tr td.select-ele::after
样式中增加pointer-events: none
就好了:查看效果