В java 8 это легко. есть два ключевых слова
Arrays.stream(intArray).forEach
::println
int[] intArray = new int[] {1, 2, 3, 4, 5};
Arrays.stream(intArray).forEach(System.out::println);
Если вы хотите напечатайте все элементы массива в одной строке, а затем используйте print
вместо println
, т. е.
int[] intArray = new int[] {1, 2, 3, 4, 5};
Arrays.stream(intArray).forEach(System.out::print);
. Другой способ без ссылки на метод просто использовать:
int[] intArray = new int[] {1, 2, 3, 4, 5};
System.out.println(Arrays.toString(intArray));
Вам нужно будет поместить возвращаемую ложную часть после функции post () в обработчик onsubmit, например:
<form onsubmit="post();return false;">
//input fields here
</form>
Вам нужно фактически вернуть false из вашего встроенного обработчика dom-0. Поэтому измените
onsubmit = "post();">
на
onsubmit = "return post();">
Или вы можете указать свою форму id и сделать это:
<form id="form1" onsubmit = "post();">
Затем из безопасное место, в котором ваш дом готов:
document.getElementById("form1").onsubmit = post;
Держите js вне DOM.
<form id="myform" action="somepage.php" method="post">
//input fields
</form>
JQuery:
$('#myform').submit(function(event){
alert('submitted');
event.preventDefault();
});
Поскольку вы добавили тег jQuery
, это лучший способ сделать это: ненавязчивое событие attach
$('form').submit(function(){
alert('the form was submitted');
return false;
});
По-вашему, это должно быть:
<form onsubmit="return post();">
Поскольку этот пост отмечен jQuery, я предлагаю следующее решение:
$('form').submit(function(e){
//prevent the form from actually submitting.
e.preventDefault();
//specify the url you want to post to.
//optionally, you could grab the url using $(this).attr('href');
var url = "http://mysite.com/sendPostVarsHere";
//construct an object to send to the server
//optionally, you could grab the input values of the form using $(this).serializeArray()
var postvars = {};
//call jquery post with callback function
$.post(url, postvars, function(response){
//do something with the response
console.log(response);
}, 'json')
});