[英]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.