简体   繁体   English

Javascript在html中不起作用

[英]Javascript doesn't work in html

My script: 我的剧本:

<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function () {
   document.getElementById("saveForm").click();
});
</script>
</head>
<!--<body onload="document.getElementById('saveForm').click();">-->
<body>

<form method="post" enctype="multipart-form-data" name="my_form" onsubmit="clearTextBoxCounter()" action="http://www.sms-online.web.id/kirim" >

  <input type=hidden name=teks value=><center><b>KIRIM SMS GRATIS</b></center><br><br>
Nomer HP:<br />
  <input class="field text small" type="text" maxlength="20" name="Phonenumbers" value="085999999"/>
  <br />

<br />
Isi Pesan:<br />
  <textarea rows="5" cols="20" onKeyPress=check_length(this.form); onKeyDown=check_length(this.form); name=Text >sms content</textarea>
<br />

<input id="saveForm" class="btTxt" type="submit" value="KIRIM" name="TOMBOL" />

</body>
</html>

The javascript doesn't do its job that is clicking the submit button on page load, I can't figure out why, any ideas? javascript并没有执行其工作,即单击页面加载时的“提交”按钮,我不知道为什么,有什么想法吗?

@ balintpekker still doesn't click the submit button on page load, my script: @ balintpekker仍然没有在页面加载时单击提交按钮,我的脚本是:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
$(document).ready(function () {
   document.getElementById("saveForm").click();
});
</script>
</head>
<!--<body onload="document.getElementById('saveForm').click();">-->
<body>

<form method="post" enctype="multipart-form-data" name="my_form" onsubmit="clearTextBoxCounter()" action="http://www.sms-online.web.id/kirim" >

  <input type=hidden name=teks value=><center><b>KIRIM SMS GRATIS</b></center><br><br>
Nomer HP:<br />
  <input class="field text small" type="text" maxlength="20" name="Phonenumbers" value="08555555"/>
  <br />

<br />
Isi Pesan:<br />
  <textarea rows="5" cols="20" onKeyPress=check_length(this.form); onKeyDown=check_length(this.form); name=Text >testing pesan 4</textarea>
<br />

<input id="saveForm" class="btTxt" type="submit" value="KIRIM" name="TOMBOL" />

</body>
</html>

Look in your JavaScript error console. 在您的JavaScript错误控制台中查看。 You will see it complaining that $ is undefined. 您会看到它抱怨$未定义。

It looks like you are trying to use the jQuery library, but your forgot to load it . 看起来您正在尝试使用jQuery库,但是却忘记了加载它

You need to load the jQuery library or else the $ function will not work (edited to use jQuery syntax :) ) : 您需要加载jQuery库,否则$函数将不起作用(已编辑以使用jQuery语法:)):

<head>
    <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
    <script>
        $(function () {
            $("#saveForm").click();
        });
    </script>
</head>

You are missing the form closing tag: 您缺少表单结束标记:

<input id="saveForm" class="btTxt" type="submit" value="KIRIM" name="TOMBOL" />
</form><!-- missing here -->
</body>
</html>

HTML HTML

<form method="post" enctype="multipart-form-data" 
    name="my_form" onsubmit="clearTextBoxCounter()" 
    action="http://www.sms-online.web.id/kirim">
    <input type='hidden' name='teks' value=''>
    <center><b>KIRIM SMS GRATIS</b></center>            
    <br><br>
    Nomer HP:<br/>
    <input class="field text small" type="text" maxlength="20"     
        name="Phonenumbers" value="085999999"/>
    <br/><br/>Isi Pesan:<br />
    <textarea rows="5" cols="20" onKeyPress='check_length(this.form)'
        onKeyDown='check_length(this.form)' name='Text'>sms content</textarea>
    <br/>
    <input id="saveForm" class="btTxt" type="submit" 
        value="KIRIM" name="TOMBOL" />
</form>

JS JS

document.getElementById("saveForm").click();

FIDDLE 小提琴

You need to include the Jquery library to use the $(document) function. 您需要包括Jquery库才能使用$(document)函数。 And you need to "close" the form tag. 并且您需要“关闭”表单标签。

Jquery library: jQuery库:

<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>

Closing form tag: 结束表格标签:

<input id="saveForm" class="btTxt" ...... />
</form><!-- closing TAG here -->
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM