1

ファイルが存在しないがリダイレクトされていない場合、新しいページでリダイレクトしようとしていますが、アラートを書き込むだけであれば動作しています。私を助けてください。

//php code

<?PHP 
if(isset($_POST["bills"]))
{
if($_POST[month]=='Select Month' || $_POST[year]=='Select Year'){$msg="Please select valid month or year";}
else if(file_exists($path.$_POST["month"].$_POST["year"].'.pdf')){header('location:'.$path.$_POST[month].$_POST[year].'.pdf');}
else{?>
<script type='text/javascript' language="javascript">document.getElementById('downloadlink').click();</script>
<?PHP }
}
?>

//html code

<form action="electricitybills.php" method="post" >
<select name="year">
<?PHP include('include/billsyear.php'); ?>
</select>
<select name="month">
<?PHP include('include/billsmonth.php'); ?>
</select>
<div class="gobutton"><input type="submit" name="bills" value="GO"></div>
</form>

    </div>
<br><br><br><a id="downloadlink" href="http://www.google.com" target="_blank" style="display:none;">link text</a></form>
4

3 に答える 3

0

jquery の .ready 関数を使用します。生成前に document.getElementById('downloadlink') にアクセスしようとしているためです。

<a id="downloadlink" href="http://www.google.com" target="_blank" style="display:none;">link text</a>
<?PHP 
if(isset($_POST["bills"]))
{
if($_POST[month]=='Select Month' || $_POST[year]=='Select Year'){$msg="Please select valid month or year";}
else if(file_exists($path.$_POST["month"].$_POST["year"].'.pdf')){header('location:'.$path.$_POST[month].$_POST[year].'.pdf');}
else{?>
<script type='text/javascript' language="javascript">
$('#downloadlink').trigger('click');

//html code

<form action="electricitybills.php" method="post" >
<select name="year">
<?PHP include('include/billsyear.php'); ?>
</select>
<select name="month">
<?PHP include('include/billsmonth.php'); ?>
</select>
<div class="gobutton"><input type="submit" name="bills" value="GO"></div>
</form>

    </div>
<br><br><br></form>

これを試してみてください。それがあなたを助けることを願っています!

于 2013-02-04T07:23:30.667 に答える
0

PHPでは、リダイレクトに使用できます:

header('location: www.google.com');

またはJavaScriptで:

location.href = "http://www.example.com/test";
于 2013-02-04T08:06:46.760 に答える
0

click()- ユーザーが手動でクリックしたかのように要素をクリックします。ほとんどのブラウザーでは、click() は「送信」または「リセット」ではないフォームの INPUT 要素でのみ機能します。リンクまたはフォーム送信ボタンのクリックをシミュレートするために使用することはできません。

downloadlink実際にはlink最も可能性が高いので、なぜ機能しないのですか

ドキュメントについては、このリンクを参照してくださいclick()

于 2013-02-04T07:12:44.807 に答える