Javascript onclick var

时间:2013-11-16 15:04:44

标签: javascript html dom

我有这个脚本:

 . '<button type="button" '.($searchQuery['can_used'] == 1 ? 'onclick="var con=confirm(\'Let op: dit is de laatste keer dat u dit bestand kan downloaden, na deze keer word het bestand automatisch verwijderd. Weet u zeker dat u deze bestand wil download?\')"' : '').' class="btn btn-info">Download het bestand...</button>'
 . '<script type="text/javascript">alert(con)</script>';

嗯,这不起作用,我收到的错误是'con is not defined'。因为当我不点击按钮时var不会存在。我无法点击按钮,因为javascript不会继续出错。我怎样才能解决这个问题?还有其他方法吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

感谢David Thomas。

通过在确认之前创建var来修复。

Uw bestand is gevonden! <br />U kunt dit bestand nog <b><u>1</b></u> keer downloaden via deze website. U kunt dit bestand tot en met <b><u>19-01-2038 04:14:07</b></u> downloaden. <br />Bestand naam: <b><u>download.rar</b></u> <br />Bestand grootte: <b><u>87.82 mb</b></u> <br /><br /><script>var con = false;</script><button type="button" onclick="con=confirm('Let op: dit is de laatste keer dat u dit bestand kan downloaden, na deze keer word het bestand automatisch verwijderd. Weet u zeker dat u dit bestand wilt downloaden?'), alert(con)" class="btn btn-info">Download het bestand...</button>

谢谢大卫。