2016-08-05 74 views
1

我只发布了部分的JavaScript代码,因为完整是一个公平的位,很多要发布在这里。但是可以找到整个html代码here简单的形式onsubmit不调用javascript函数(jQuery)

powerInput()不会被调用。我只是无法弄清楚如何在Jquery中编写代码。任何帮助都会很棒。

function someFunction(){ 

$('#second').append('$${t}^x\\sqrt{t}^x$$'); 
      $('#container').append('<div id="third" ondrop="drop(event)" ondragover="allowDrop(event)"></div>'); 

$('#third').append('<form onsubmit="powerInput()">'); 

$('#third').append('<span style="position:absolute; top: 10px; left: 50px;">$${t}\\sqrt{t}$$</span>').css("font-size","200%"); 

$('#third').append('<input type="text" name="fpower" maxlength="1" style="width: 10px; height:9px; position:absolute; top:27px; left: 60px;">'); 

$('#third').append('<input type="text" name="spower" maxlength="1" style="width: 10px; height:9px; position:absolute; top: 25px; left:100px;">'); 

$('#third').append('<input type="submit">'); 
$('#third').append('</form>'); 

} 

function powerInput(){ alert("test"); 
} 
+0

而不是内联处理程序,使用jQuery的on()来绑定事件。 '('submit',function(){'。 – Tushar

+0

函数是OK。我认为问题在于你在哪里调用它 – jonju

回答

0

你正在附加错误,你不能追加HTML标记的一部分到dom中,将整个代码追加到一个字符串中。你现在的表单将没有任何元素。

$('#third').append('<form onsubmit="powerInput()">' + 
    '<span style="position:absolute; top: 10px; left: 50px;font-size: 200%">$${t}\\sqrt{t}$$</span>' + 
    '<input type="text" name="fpower" maxlength="1" style="width: 10px; height:9px; position:absolute; top:27px; left: 60px;">' + 
    '<input type="text" name="spower" maxlength="1" style="width: 10px; height:9px; position:absolute; top: 25px; left:100px;">' + 
    '<input type="submit">' + 
    '</form>'); 
+0

谢谢@Musa它完美的工作。谢谢 –

0

尝试调试脚本。按f12并查看您是否在浏览器控制台中遇到任何错误。可能有一些脚本错误

0

尝试添加所有的HTML标签符合或检查元素,看看他们是否正确添加所需格或标签
如果他们添加正确的,只要你想添加那么它正常运行 因为如果有错误在追加和格式化它将不会提前执行