[英]i want to hide or show button according to table data
I want to hide or show button according to table data. 我想根据表格数据隐藏或显示按钮。 If data is 0 then button show else hide
如果数据为0,则按钮显示否则隐藏
<?php
$variable="SELECT * FROM tabel";
$variable1=mysql_query($variable);
$count=1;
$variable2=mysql_fetch_array($variable1)
?>
<?php
$t=$variable2['paid'];
?>
<script>
var payment_link='<?php echo $t ?>';
if (payment_link=='0') {
$('#send').hide();
}
else {
$('#send').show();
}
</script>
<buttonid="send">SEND</button>
The problem is, that the javascript is executed before the button gets even rendered. 问题是,在按钮被渲染之前就执行了javascript。 This is why javascript can't change it yet.
这就是为什么javascript不能更改它的原因。
Two possibilities: 两种可能性:
Move the <script>
part below the <button>
将
<script>
部分移到<button>
下面
or wrap it in a $( document ).ready(function() { // your code })
: 或将其包装在
$( document ).ready(function() { // your code })
:
<script>
$(document).ready(function() {
var payment_link='<?php echo $t ?>';
if (payment_link=='0') {
$('#send').hide();
}
else {
$('#send').show();
}
});
</script>
Also make sure to have a space between 'button' and 'id': 另外,请确保在“按钮”和“ id”之间留一个空格:
<button id="send">SEND</button>
Is the space missing between button and id in the below line? 下一行的button和id之间是否缺少空格?
<buttonid="send">SEND</button>
If that is the case, please change to: 如果是这种情况,请更改为:
<button id="send">SEND</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.