我正在尝试使用圆形形状和选项值死点来实现此选择选项。这是一个快照:
到目前为止,这是我的代码:
<select size="4">
<option value="s">S</option>
<option value="l">L</option>
<option value="xl">XL</option>
<option value="xxl">XXL</option>
</select>
select {
display:table-row;
}
option {
display:table-cell;
width: 50px;
height: 50px;
background-color: green;
border-radius: 50%;
padding-top: 20px;
padding-left: 20px;
}
结果:
它真的可以实现吗?我可以使用 span 和 div 以及 jQuery 来做到这一点,但我需要在没有 JS 的情况下直接将表单提交给 PHP。
谢谢
最佳答案
是的,为什么不呢。使用类 DOMDocument我们做得到... 示例:
<?php
$dom = new DOMDocument();
//uncomment any one of these
//$dom->loadHTML("index.html");//for html file
//$dom->loadHTML(file_get_contents('http://localhost/index.php'));//for php file
//to get element
$div = $dom->getElementsByTagName('div');
//to get element array and get its attributes
$divs = $dom->getElementsByTagName('div');
foreach ($divs as $div) {
foreach ($div->attributes as $attr) {
$name = $attr->nodeName;
$value = $attr->nodeValue;
echo "Attribute '$name' :: '$value'<br />";
}
}
//to get specific element without array
$div = $dom->getElementById('divID');
这只是一个示例,您可以使用我的答案顶部给出的 domdocument 类引用来做更多的事情,以检查我们可以做更多的事情。
另一种选择是制作一个表单并使用 $_POST 访问它超全局变量,但也许这需要一个按钮来提交。当然,这种方法比 domdocument 类更值得推荐。所以我分享了两个选项,你选择哪个取决于你
关于php - 带有 css 的圆形选择选项(PHP 可处理)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46871006/