<form id="1" method="post">
<input type="text" name="url" id="url" />
<input name="submit" type="submit">
</form>
<form id="2" action="http://www.domain1.com/form1.php?url=url from form1 input field" method="post"></form>
我尝试了很多,但我无法理解。 ((jQuery):追加,onblur等等)
当我在form1中键入一个URL时,我想将url复制到form2操作,之后?url = 其他网址应该只包含www没有http:// 按下1提交按钮并发布两个表格。
答案 0 :(得分:0)
我没有使用两种形式,只有两种div。
$("#submit").on('click',function(){
$("#2").attr("action",$("#url").val());
});
查看JSFIDDLE
答案 1 :(得分:0)
$('#1').find('#url').bind('keyup',function(){
var inputValue = $(this).val();
$('#2').attr('action','http://www.domain1.com/form1.php?url='+inputValue);
});
答案 2 :(得分:0)
试一试:
<form id="frmOne" method="post">
<input type="text" name="url" id="url" value="www.url.com">
<input name="submit" type="submit">
</form>
<form id="frmTwo"></form>
<div id="txtMessage"></div>
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>
<div class="progress progress-striped active">
<div class="progress-bar" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 45%">
<span class="sr-only">45% Complete</span>
</div>
</div>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="btnAccount">Access your account</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
//Cache variables
var $frmOne = $('#frmOne'),
$frmTwo = $('#frmTwo'),
$txtMessage = $('#txtMessage'),
frmTwoAction = 'http://www.domain1.com/form1.php?url=',
$myModal = $('#myModal');
//Form 1 sumbit event
$frmOne.on('submit', function (event) {
event.preventDefault();
var strUrl = $frmOne.find('#url').val();
//validation
if (strUrl === ''){
$txtMessage.html('<b>Missing Information: </b> Please enter a URL.');
} else if (strUrl.substring(0, 7) === 'http://') {
//Clear field
$frmOne.find('#url').val('');
$txtMessage.html('<b>http://</b> is not supported!');
} else if (strUrl.substring(0, 4) !== 'www.') {
//Clear field
$frmOne.find('#url').val('');
$txtMessage.html('<b>Invalid URL</b> Please enter a valid URL!');
} else {
//You can update these here if you want
$myModal.find('.modal-title').text('Adding new Modal Title from jQuery');
//$myModal.find('.modal-body p').text('Adding new Modal body from jQuery');
//Open modal
$myModal.modal('show');
//Setup click event on button in modal
$('#btnAccount').on('click', function(e){
//goto page location
document.location = 'http://www.ACCOUNT-URL.com';
});
//set form action and submit form
//$frmTwo.attr('action', frmTwoAction + strUrl).submit();
//return true; // let form one submit now!
}
return false;
});
</script>
答案 3 :(得分:-1)
myVar = $("#id").val();
$("#2").attr("action", myVar);
应该工作,但没有测试过。