将外部Javascript放在Php文件中

时间:2015-06-11 12:52:23

标签: javascript php forms

我有一个外部Javascript应该放在html类型文档的head部分,但是我的网站严格来说是php。

<?php
$the_title = 'Welcome!';
$the_content = '<p>We are still working out the kinks!  The sign up page works, so feel free to sign up!  We will send out a welcome message when we finish!  Cheers.<br />
<form action="http://meledie39spicks.wildapricot.org/Sys/Login" method="post">
        <input type="hidden" name="ReturnUrl" value="">
        <input type="hidden" name="browserData" id="idLoginBoxBrowserField">

        <input name="email" type="email" placeholder="Email Address" maxlength="100"/>
        <input type="password" name="password" placeholder="Password">

        <input type="checkbox" name="rememberMe" id="idLoginBoxRememberMeCheckbox">
        <label for="idLoginBoxRememberMeCheckbox">Remember me</label>
        <input type="submit" class="loginBoxLoginButton" tabindex="4" value="Login">
    </form>';
?>

<?php include('single.php'); ?>

我需要放置javascript:

  <script src="http://www.wildapricot.com/docs/scripts/waloginbox.js></script>

某处以使表单正常工作。我试过把它直接放在表格之后,这种表现有一定程度的重大故障。我也尝试在我的代码编辑器告诉我存在语法错误的表单之后回显脚本。我还是新手,所以现在我不知所措。还有其他建议吗?谢谢:)

3 个答案:

答案 0 :(得分:0)

您可以在需要的地方echo出来。

echo '<script src="http://www.wildapricot.com/docs/scripts/waloginbox.js></script>';

答案 1 :(得分:0)

我试着写评论,但事情没有发生。

 <?php
 echo  '<script src="http://www.wildapricot.com/docs/scripts/waloginbox.js"></script>';
 echo $the_title = 'Welcome!';
 echo $the_content = '<p>We are still working out the kinks!  The sign up page works, so feel free to sign up!  We will send out a welcome message when we finish!  Cheers.<br />
    <form action="http://meledie39spicks.wildapricot.org/Sys/Login" method="post">
    <input type="hidden" name="ReturnUrl" value="">
    <input type="hidden" name="browserData" id="idLoginBoxBrowserField">

    <input name="email" type="email" placeholder="Email Address" maxlength="100"/>
    <input type="password" name="password" placeholder="Password">

    <input type="checkbox" name="rememberMe" id="idLoginBoxRememberMeCheckbox">
    <label for="idLoginBoxRememberMeCheckbox">Remember me</label>
    <input type="submit" class="loginBoxLoginButton" tabindex="4" value="Login">
</form>';
  ?>

  <?php include('single.php'); ?>

您需要在文件的顶部显示echo

答案 2 :(得分:0)

<?php
echo '<script src="http://www.wildapricot.com/docs/scripts/waloginbox.js"></script>';
$the_title = 'Welcome!';
$the_content = '<p>We are still working out the kinks!  The sign up page works, so feel free to sign up!  We will send out a welcome message when we finish!  Cheers.<br /></p>

<form action="http://meledie39spicks.wildapricot.org/Sys/Login" method="post">
        <input type="hidden" name="ReturnUrl" value="">
        <input type="hidden" name="browserData" id="idLoginBoxBrowserField">

        <input name="email" type="email" placeholder="Email Address" maxlength="100"/>
        <input type="password" name="password" placeholder="Password">

        <input type="checkbox" name="rememberMe" id="idLoginBoxRememberMeCheckbox">
        <label for="idLoginBoxRememberMeCheckbox">Remember me</label>
        <input type="submit" class="loginBoxLoginButton" tabindex="4" value="Login">
    </form>'; 

?>

<?php include('single.php'); ?>