Bootstrap在php中动态设置模态标题

时间:2015-10-28 13:45:22

标签: javascript php jquery twitter-bootstrap

我一直试图从php远程改变我的模态标题。我想要设置的标题是一个变量,并且已经分配,​​但是当用户输入新内容时它会发生变化。

这是我的php代码:

$Studname = $results['Studentname'];
echo '<script type="text/javascript">';                
echo 'alert("'.$Msg.$Studname.'")';
echo '</script>';

echo "<script type='text/javascript'>
    $(document).ready(function(){
        $('#MyAdvertLabel').text(".$Studname.");
    });
</script>";

echo "<script type='text/javascript'>
    $(document).ready(function(){
        $('#myAdvert').modal('show');
    });
</script>";

根据我正在使用的程序,代码似乎没有错误,但是当我运行代码时,模态标题没有变化。

1 个答案:

答案 0 :(得分:1)

您的PHP将生成Javascript错误:

<?php
$Studname = 'Sample text';
$('#MyAdvertLabel').text(".$Studname.");
?>

将生成:

$('#MyAdvertLabel').text(sample text);

text()函数的内容需要用引号括起来。

例如:

<?php
$Studname = 'Sample text';
$('#MyAdvertLabel').text('".$Studname."'); // Notice the ' ' wrapping the variable
?>
相关问题