问题
I am trying to insert the following:
<div class="modal fade" id="modalForwardMail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Forward this Mail</h4>
</div>
<div class="modal-body"><center>
<form name="contactform" method="post" action="forwardForm.php" class="form-horizontal" role="form">
<input type="email" class="form-control" placeholder="Receiver Email Address" name="forwardEmail">
<input class="form-control" placeholder="Full Name" type="text" value={{currentUser.get('fullName')}} name="fullName">
<input class="form-control" placeholder="Subject" type="text" name="subject">
<input class="form-control" placeholder="Sender Email Address" value={{currentUser.get('username')}} type="text" name="email">
<br><textarea class="form-control" rows="5" placeholder="Notes" name="message" cols="30"></textarea>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<input type="submit" class="btn btn-default" name="submit" value="Submit">
</form></center>
<h3></h3>
</div>
</div>
</div>
</div>
Into:
$('button.forward').click(function() {
});
Below is the entire jquery code:
var UploadMessage = Parse.Object.extend("Upload");
var querym = new Parse.Query(UploadMessage);
querym.equalTo("user", currentUser);
querym.equalTo("Type", "Letter");
querym.descending("createdAt");
querym.find({
success: function(querym) {
//alert("Successfully retrieved " );
// Do something with the returned Parse.Object values
for (var i = 0; i < querym.length; i++) {
var object = querym[i];
(function($) {
$('#mail-table').append('<tr class="results-row"><td>' + object.get('Date') + '</td><td>' + object.get('Subject') + '</td><td>' + object.get('Sender')
+ '</td></tr><tr class="expandMail"><td colspan="3">'
+'<label id="action"><button type="button" class="btn btn-default" data-toggle="modal" data-target="#modalForwardMail" id="actionButton1"><i class="fa fa-share"></i>  Forward</button></label> <label id="action"><button class="btn btn-default" id="actionButton2"><i class="fa fa-recycle"></i>  Delete</button></label> </center><br /><label id="uploadedInfo">' + object.get('Message') +
'<br /> </label> <br /> <a href=" '+ object.get('documentURL') +' " target="_blank"> <img height="175" width="120" src="content/scan.png" alt="Image" id="previewThumb" class="img-responsive"></a><br /><a href=" '+ object.get('documentURL') +' " target="_blank"> <button id="actionButton1" class="downloadButton"> <i class="fa fa-download fa-2x"></i>  Download</button></a><br />' + '</td></tr>');
})(jQuery);
//alert(object.id + ' - ' + object.get('playerName'));
}
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
$(document).on('click' , '.results-row', function () {
$(this).next('.expandMail').toggle();
$('button.delete').click(function() {
$(this).parent().parent().prev().remove();
$(this).parent().parent().remove();
});
$('button.forward').click(function() {
$("#modalForwardMail").modal("now");
});
});
The reason why I want to do that is because I want to grab object.get('documentURL')
from the jquery function and insert it into the form so the end result looks like this:
<div class="modal fade" id="modalForwardMail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Forward this Mail</h4>
</div>
<div class="modal-body"><center>
<form name="contactform" method="post" action="forwardForm.php" class="form-horizontal" role="form">
<input type="email" class="form-control" placeholder="Receiver Email Address" name="forwardEmail">
<input class="form-control" placeholder="Full Name" type="text" value={{currentUser.get('fullName')}} name="fullName">
<input class="form-control" placeholder="Subject" type="text" name="subject">
<input class="form-control" placeholder="Sender Email Address" value={{currentUser.get('username')}} type="text" name="email">
<br><textarea class="form-control" rows="5" placeholder="Notes" name="message" cols="30"></textarea>
object.get('documentURL')
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<input type="submit" class="btn btn-default" name="submit" value="Submit">
</form></center>
<h3></h3>
</div>
</div>
</div>
</div>
回答1:
From what I understood you want to show form in a modal onclick of Forward link.So here is the code
html
<a data-toggle="modal" href="http://fiddle.jshell.net/bHmRB/51/show/" data-target="#myModal" id="getModal">Forward</a>
<div class="modal fade" id="modalForwardMail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" ><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Forward this Mail</h4>
</div>
<div class="modal-body"><center>
<form name="contactform" method="post" action="forwardForm.php" class="form-horizontal" role="form">
<input type="email" class="form-control" placeholder="Receiver Email Address" name="forwardEmail">
<input class="form-control" placeholder="Full Name" type="text" value={{currentUser.get('fullName')}} name="fullName">
<input class="form-control" placeholder="Subject" type="text" name="subject">
<input class="form-control" placeholder="Sender Email Address" value={{currentUser.get('username')}} type="text" name="email">
<br><textarea class="form-control" rows="5" placeholder="Notes" name="message" cols="30"></textarea>
<div id="url"></div>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<input type="submit" class="btn btn-default" name="submit" value="Submit">
</form></center>
<h3></h3>
</div>
</div>
</div>
</div>
jquery
$(document).ready(function(){
$('#getModal').click(function() {
var pageURL = $(location).attr("href");
$("#url").text(pageURL);
$("#modalForwardMail").modal("toggle");
// alert(pageURL);
});
});
DEMO1
with document.Url as you specified in comments below. DEMO2
来源:https://stackoverflow.com/questions/28349522/inserting-html-code-within-a-jquery-function