基于php变量改变图像的javascript 你的交易很成功!任何进一步通信的交易参考号为。
我有这个html。我想要的是javascript,它可以在$message='success'时将img src更改为基于php变量改变图像的javascript 你的交易很成功!任何进一步通信的交易参考号为。,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我有这个html。我想要的是javascript,它可以在$message='success'时将img src更改为,在$message='failed'时将其更改为 <div style="margin-left:5%;width:5%;float:left;margin-right:10%;"> <img src="./1.png" id="imgstatus"/> </div> <div style="width:80%;float:left
,在$message='failed'
时将其更改为
<div style="margin-left:5%;width:5%;float:left;margin-right:10%;">
<img src="./1.png" id="imgstatus"/>
</div>
<div style="width:80%;float:left;">
<h3>Your transaction was <?php echo $message; ?> ! Your transaction reference number for any furthur communication is <?php echo $cust_ref_no; ?> .</h3>
</div>
</div>
“id=”imgstatus“/>
您的交易是!您的任何进一步通信的交易参考号是。
您可以使用三元运算符来最小化代码长度
<div style="margin-left:5%;width:5%;float:left;margin-right:10%;">
<img src="<?php
if($message == 'success')
{
echo 'success.jpg';
}
else
{
echo 'failed.jpg';
}
?>" id="imgstatus"/>
</div>
<div style="width:80%;float:left;">
<h3>Your transaction was <?php echo $message; ?> ! Your transaction reference number for any furthur communication is <?php echo $cust_ref_no; ?> .</h3>
</div>
</div>
“id=”imgstatus“/>
你的交易很成功!任何进一步通信的交易参考号为。
是否希望根据$message变量的值或更短的值显示或隐藏图像:“/>
<div style="margin-left:5%;width:5%;float:left;margin-right:10%;">
<img src="<?php echo ($message == 'success' ? 'success.jpg' : 'failed.jpg'); ?>" id="imgstatus"/>
</div>
<div style="width:80%;float:left;">
<h3>Your transaction was <?php echo $message; ?> ! Your transaction reference number for any furthur communication is <?php echo $cust_ref_no; ?> .</h3>
</div>
</div>