我点击提交按钮以确保其正常工作后回复javascript,但它只关闭模式并刷新页面。怎么了? 我也试过了 'if($ _ POST [projectSubmit']而不是将它封装在isset()上。但它无法识别索引'projectSubmit'
<form action="" method="POST">
<div id="modal1" class="modal modal-fixed-footer" style="width:35%;">
<div class="modal-content">
<h4>Create Project</h4>
<div class="row">
<div class="input-field col s12">
<i class="material-icons prefix">perm_identity</i>
<input type="text" name="projectName" class="validate">
<label for="projectName" class="">Project Name</label>
</div>
<div class="input-field col s12">
<i class="material-icons prefix">room</i>
<label for="projectLocation">Location</label>
<input type="text" name="projectLocation">
</div>
<div class="input-field col s12">
<label for="projectType">Project Type</label><br>
<input name="projectType" type="radio" value="Condominium" id="test1" />
<label for="test1" class="black-text">Condominium</label>
<input name="projectType" type="radio" value="Housing" id="test2" />
<label for="test2" class="black-text">Housing</label>
</div>
</div><!--ROW-->
</div>
<div class="modal-footer">
<input type="submit" name="projectSubmit"class="waves-effect waves-green btn-flat" value="s">
<button type="RESET" class="btn btn-flat">RESET</button>
</div>
</div>
<?php
if(isset($_POST['projectSubmit'])){
echo "<script type='text/javascript>alert('JUJU');</script>";
}
else{
echo "<script type='text/javascript>alert('xx');</script>";
}
?>
</form>
答案 0 :(得分:4)
你没有在text / javascript之后完成单引号。 请按如下方式更新:
echo "<script type='text/javascript'>alert('JUJU');</script>";
和更新第二个回声相同:
echo "<script type='text/javascript'>alert('xx');</script>";
答案 1 :(得分:1)
java脚本标记不正确(缺少引号)
您的代码
echo "<script type='text/javascript>alert('JUJU');</script>";
更正标签
echo "<script type='text/javascript'>alert('JUJU');</script>";