所有的按钮都在表单中,自动提交表单,但我需要其他按钮功能。
代码如下:
<html lang="en">
<title>NTF Catering Service</title>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script src="js/js.1.js" type="text/javascript"></script>
</head>
<body>
<form action="create.php" method="post">
<select multiple="multiple" class="options" id="textarea">
<option value="item1">Item 1</option>
<option value="item2">Item 2</option>
<option value="item3">Item 3</option>
<option value="item4">Item 4</option>
<option value="item5">Item 5</option>
</select>
<button id="copy">Copy</button>
<button id="remove">Remove</button>
<select id="textarea2" multiple class="remove">
<input type="submit" name="submit" />
</form>
</select>
</html>发布于 2014-01-22 19:24:07
如果您的意思是所有按钮都提交表单,则将以下内容添加到元素中:type="button"
<button type="button" id="copy">Copy</button>
<button type="button" id="remove">Remove</button>这应确保只有将提交表单
然后通过你的jquery代码控制它们:
$('#copy').on('click', function(e){ ///do stuff here });
$('#remove').on('click', function(e){ ///do stuff here });或者在按钮上添加onclick:
<button onclick="someCopyfunction();" type="button" id="copy">Copy</button>
<button onclick="someRemovefunction();" type="button" id="remove">Remove</button>等
发布于 2014-01-22 19:25:53
由于您已经标记了jQuery和Javascript,因此您还可以使用:
$('input[name="submit"]').click(function(event){
event.preventDefault();
//Do other stuff here
});发布于 2014-01-22 19:34:47
默认情况下,<button>标记是submit按钮,以使它们只使用按钮
<button type="button">copy</button>
<button type="button">Remove</button>检查此what's the standard behavior when < button > tag click? will it submit the form?
注释始终为<button>元素指定类型属性。不同的浏览器对元素使用不同的默认类型。
使用<input>在HTML表单中创建按钮。
https://stackoverflow.com/questions/21281503
复制相似问题