我想将url添加/附加到表单操作属性。我该怎么做呢?我有下面的代码,但不起作用,因为我正在使用AHAH(异步HTML over HTTP)方法在页面上加载html表单
//load submission form
$(document).ready(function() {
jQuery("#submit-a-request").load( 'http://draftsite.com/submit-a-request' + ' #item-submission');
}); // ready
//submission form
$(document).ready(function(){
$('#item-submission').attr('action', 'http://draftsite.com');
}); // ready
<form id="item-submission" action="/submit-a-request/maintenance-request/a2db427bfdc794d3695d8ac6843cb04d" method="post" name="submissionForm" accept-charset="utf-8" enctype="multipart/form-data">
<input type="text" name="elements[0c7f7be5-059b-4cd3-8641-d88f4199af01][0][value]" value="" size="60" maxlength="255">
<input type="text" name="elements[bc797942-f95f-438e-ad05-e44b2199e9a8][0][value]" value="" size="60" maxlength="255">
<
<textarea name="elements[169f7b63-e778-4a1b-ac22-654c2e248bca][0][value]" cols="60" rows="20">Floor Number / Room Description</textarea>
<input type="hidden" name="option" value="com_zoo">
<input type="hidden" name="controller" value="submission">
<input type="hidden" name="task" value="save">
<input type="hidden" name="8958a901f9a45927058aef098665efa5" value="1">
</form>
答案 0 :(得分:0)
您需要在load()
竞争回调
$(document).ready(function() {
var url = 'http://draftsite.com/submit-a-request' + ' #item-submission'
$("#submit-a-request").load( url , function(){
// new html exists, can modify it now
$('#item-submission').attr('action', function(_, action){
return 'http://draftsite.com' + action;
});
});
}); // ready
答案 1 :(得分:0)
请在此片段中找到添加和追加属性的扩展方法,您可以通过 jQuery.fn.extend() 来实现此目的,请检查它对您肯定有帮助
jQuery.fn.extend({
AddAttribute: function(attr) {
return this.each(function() {
$(this).attr("action",attr)
});
},
AppendAttribute: function(attr) {
return this.each(function() {
var existingattr= $(this).attr("action");
$(this).attr("action",attr + existingattr)
});
}
});
$(document).ready(function() {
jQuery("#submit-a-request").load( 'http://draftsite.com/submit-a-request' + ' #item-submission' , function() {
//Add attribute
$('#item-submission').AddAttribute('http://draftsite.com');
//Or append Attribute
$('#item-submission').AppendAttribute('http://draftsite.com');
});
}); //
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="item-submission" action="/submit-a-request/maintenance-request/a2db427bfdc794d3695d8ac6843cb04d" method="post" name="submissionForm" accept-charset="utf-8" enctype="multipart/form-data">
<input type="text" name="elements[0c7f7be5-059b-4cd3-8641-d88f4199af01][0][value]" value="" size="60" maxlength="255">
<input type="text" name="elements[bc797942-f95f-438e-ad05-e44b2199e9a8][0][value]" value="" size="60" maxlength="255">
<input type="hidden" name="option" value="com_zoo">
<input type="hidden" name="controller" value="submission">
<input type="hidden" name="task" value="save">
<input type="hidden" name="8958a901f9a45927058aef098665efa5" value="1">
</form>
&#13;