[英]i want to hide or show button according to table data
我想根据表格数据隐藏或显示按钮。 如果数据为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>
问题是,在按钮被渲染之前就执行了javascript。 这就是为什么javascript不能更改它的原因。
两种可能性:
将<script>
部分移到<button>
下面
或将其包装在$( 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>
另外,请确保在“按钮”和“ id”之间留一个空格:
<button id="send">SEND</button>
下一行的button和id之间是否缺少空格?
<buttonid="send">SEND</button>
如果是这种情况,请更改为:
<button id="send">SEND</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.