如何从带有jquery的表单中获取操作URL?
获取表单,询问action
属性:
$('#myForm').attr('action');
通常,在抓住这些类型的值时,最好使用prop()
而不是attr()
。 (这个prop() vs attr() stackoverflow post解释了原因。)
但是,在这种情况下,@JAAulde answer正是我所需要的,但不是你需要的。您可能需要完整的操作网址。
<form action="handler.php" method="post" id="myForm">
$('#myForm').attr('action');
// returns 'handler.php'
$('#myForm').prop('action');
// returns 'http://www.example.com/handler.php'
Check out the cool ascii table in this stackoverflow post了解更多。
要使用表单的action属性,请使用:
$( '#myForm' ).attr( 'action' );
像@JAAulde说的那样。
要使用表单中输入的值,请使用:
$('#myInput').val();
试试这个:
var formAction = $('#form')[0].action;
或者在表格提交上:
$("#form").submit(function (event) {
event.preventDefault();
var frmAction=this.action;
});