Forms Mootools在提交时形成,没有domready

Forms Mootools在提交时形成,没有domready,forms,mootools,Forms,Mootools,下面的mootools代码没有任何错误。我想做的是在第二个代码块上使用onsubmit事件重写它,而不使用domready。谢谢 <html> <head> <title>Simplest Form Ajax</title> <script type="text/javascript" src="../mootools/mootools-core-1.3.2fc.js"></script> <scrip

下面的mootools代码没有任何错误。我想做的是在第二个代码块上使用onsubmit事件重写它,而不使用domready。谢谢

<html> 
<head>  
<title>Simplest Form Ajax</title> 
<script type="text/javascript" src="../mootools/mootools-core-1.3.2fc.js"></script>
    <script type="text/javascript">
    window.addEvent('domready', function() {
        $('myForm').addEvent('submit', function(e) { 
            e.stop();
            this.set('send', {
                onComplete: function(response) {
                    $('log_res').set('html', response);
                }
            });
            this.send();
        });
    });    
</script>
</head>  
<body> 
<h3>Send a Form with Ajax</h3>
<form id="myForm" action="ajaxRes.php" method="post">
    <div>
        <p>Enter something:
            <input type="text" name="something" value="John" />
            <input type="submit" />
        </p>
    </div>
</form></br></br>
<h3>Ajax Response</h3>
<div id="log_res"></div>
</body>
</html>
未完成的代码:

<html> 
<head>  
<title>Simplest Form Ajax</title> 
<script type="text/javascript" src="../mootools/mootools-core-1.3.2fc.js"></script>
    <script type="text/javascript">
    function loadMe() { 
          ...
    }); 
</script>
</head>  
<body> 
<h3>Send a Form with Ajax</h3>
<form id="myForm" action="ajaxRes.php" onsubmit="loadMe()" method="post">
    <div>
        <p>Enter something:
            <input type="text" name="something" value="John" />
            <input type="submit" />
        </p>
    </div>
</form></br></br>
<h3>Ajax Response</h3>
<div id="log_res"></div>
</body>
</html>

可以使用带有javascript:前缀的表单的action属性

以下可能是未测试的可能实现代码:

<html> 
<head>  
<title>Simplest Form Ajax</title> 
<script type="text/javascript" src="../mootools/mootools-core-1.3.2fc.js"></script>
    <script type="text/javascript">
    function submit() { 
          var obj = {};
          ["something","somethingElse"].each(function(n) {
                obj[n] = ("myForm").getElement("input[name="+n+"]").get("value");
          });
          new Request.HTML({"url" : "ajaxRes.php"}).addEvent("success", function(resp) {$("log_res").adopt(resp);}).post(obj);
    }); 
</script>
</head>  
<body> 
<h3>Send a Form with Ajax</h3>
<form id="myForm" action="javascript:submit()" method="post">
    <div>
        <p>Enter something:
            <input type="text" name="something" value="John" />
            <input type="text" name="somethingElse" value="John" />
            <input type="submit" />
        </p>
    </div>
</form></br></br>
<h3>Ajax Response</h3>
<div id="log_res"></div>
</body>
</html>

干杯

你为什么喜欢第二个街区?第一个被认为是优雅的解决方案。如果伤害眼睛,请将其移动到外部文件: