作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我看过几篇关于使整个 div 可点击的帖子,但我希望让它可以选择。
我拥有的是一个 php while 循环,它根据用户在 mySQL 数据库中的条目显示一个表。该代码如下所示:
<div class='tracksub'>
<div class='headname'><div class='headtext'>Name</div></div>
<div class='headtype'><div class='headtext'>Type</div></div>
<div class='headbrand'><div class='headtext'>Brand</div></div>
<div class='headedp'><div class='headtext'>EDP</div></div>
<div class='headdiameter'><div class='headtext'>Diameter</div></div>
<div class='headflutes'><div class='headtext'>Flutes</div></div>
<!-- <div class='headaddremove'><div class='headtext'>Add/Remove Tool</div></div> -->
</div>";
$i = 0;
while($row = mysqli_fetch_assoc($resulttable)){
if($i%2 == 0){
echo "<div class='even' id='" . $row['pKey'] . "'>";
echo "<div class='name'><div class='tracktext'><a class='tracklink'>" . $row['name'] . "</a></div></div>";
echo "<div class='type'><div class='tracktext'>" . $row['type'] . "</div></div>";
echo "<div class='brand'><div class='tracktext'>" . $row['brand'] . "</div></div>";
echo "<div class='edp'><div class='tracktext'>" . $row['part_number'] . "</div></div>";
echo "<div class='diameter'><div class='tracktext'>" . $row['cutting_diam'] . "</div></div>";
echo "<div class='flutes'><div class='tracktext'>" . $row['flutes'] . "</div></div>";
//echo "<div class='addremove'><form id='addremove' method='POST' action=''><button type='submit' class='addbtn' name='add" . $row['pKey'] . "'>Add</button><button type='submit' class='removebtn' name='remove" . $row['pKey'] . "'>Remove</button></form></div>";
echo "</div>";
} else {
echo "<div class='odd'>";
echo "<div class='name'><div class='tracktext'><a href='" . $row['image'] . "'>" . $row['name'] . "</a></div></div>";
echo "<div class='type'><div class='tracktext'>" . $row['type'] . "</div></div>";
echo "<div class='brand'><div class='tracktext'>" . $row['brand'] . "</div></div>";
echo "<div class='edp'><div class='tracktext'>" . $row['part_number'] . "</div></div>";
echo "<div class='diameter'><div class='tracktext'>" . $row['cutting_diam'] . "</div></div>";
echo "<div class='flutes'><div class='tracktext'>" . $row['flutes'] . "</div></div>";
//echo "<div class='addremove'><form id='addremove' method='POST' action=''><button type='submit' class='addbtn' name='add" . $row['pKey'] . "'>Add</button><button type='submit' class='removebtn' name='remove" . $row['pKey'] . "'>Remove</button></form></div>";
echo "</div>";
}
if(isset($_POST['add' . $row['pKey'] .''])){
$add = $row['pKey'];
$sql = "UPDATE `cutting tools` SET `qty` = `qty` + 1 WHERE `pKey` = '$add'";
$conn->query($sql);
}
if(isset($_POST['remove' . $row['pKey'] .''])){
$remove = $row['pKey'];
$sql = "UPDATE `cutting tools` SET `qty` = `qty` - 1 WHERE `pKey` = '$remove'";
$conn->query($sql);
}
$i++;
}
echo "</div>";
<div class="rightbox">
<div class="tbdrawer">
</div>
<div class="bininfo">
<div>
<div class="toolimg">
<img src="" /> <!--src comes from selected mySQL row -->
</div>
<div class="toolinfoextra">
<!-- a couple rows of additional info go here -->
</div>
</div>
if(isset($_POST['. $row['pKey'] .'])){ //where the buttons name is the primary key
$imglink = $row['image'];
$length = $row['length'];
}
"<script type="text/javascript">
$( "#" . $row['pKey'] . "" ).focus(function() {"
$imglink = $row['image'];
"});
</script>"
最佳答案
这是一个错误的方法 - 你应该做这样的事情:
<ul>
<?php
$i = 0;
while($row = mysqli_fetch_assoc($resulttable)){
echo<<<END
<a class="table-link" id="$i" href="#">
END;
if(i%2==0){
echo "<li class='odd'>";
} else {
echo "<li class='even'>";
}
echo <<< END
...
(here all div's)
...
</li>
</a>
<div id="modal-$i" class="rightbox">
<div class="tbdrawer">
</div>
<div class="bininfo">
<div>
<div class="toolimg">
<img src="" /> <!--src comes from selected mySQL row -->
</div>
<div class="toolinfoextra">
<!-- a couple rows of additional info go here -->
</div>
</div>
</div>
</div>
END;
i++;
}
?>
</ul>
a.table-link:hover {
opacity: 0.8; // for e.g.
}
a.table-link:clicked {
background-color: blue;
}
.rightbox {
display: none;
}
.show {
display: block;
position: relative;
z-index: 1000;
top: 50px;
background-color: white;
}
for(el in document.getElementsByClassName('table-link')) {
el.onclick = () => {
document.getElementById('modal-$i')[0].classes.add('show')
return false // for cancel redirecting of href
}
}
onclick
这将删除类
show
从你的模态。
关于javascript - 如何使整个 <div> 可选?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59621466/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!