我一直试图找到一种方法来复制此表单及其输入字段几天。我尝试过使用我发现here的代码,但无济于事。如何复制此表单?
HTML
<form action="dilemman.php" method="post" class="copy" enctype="multipart/form-data">
Video: <br>
<input type="text" rows="1" cols="40" name="video"></textarea>
<div class="input_fields_wrap">
<button class="add_field_button">Lägg till fler svar</button>
</div>
<a href="#" class="copy" rel=".form">Duplicate form</a>
</form>
的Javascript
var removeLink = ' <a class="remove" href="#" onclick="$(this).parent().remove(); return false">remove</a>';
$('a.copy').relCopy({limit: 5, append: removeLink});
答案 0 :(得分:1)
Html:
<button onclick="myFunction()">Duplicate form</button>
JS:
function myFunction() {
var elmnt = document.getElementById("formid");
var cln = elmnt.cloneNode(true);
document.body.appendChild(cln);
}
答案 1 :(得分:1)
你只能使用jquery,不需要使用relCopy ..
http://codepen.io/mkdizajn/pen/jWEYeB
var cp = $('form.copy').html();
$('a.copy').on('click', function(){
$('form.copy').append( cp );
})
HTH
答案 2 :(得分:0)
快速查看relCopy
文档,您必须使用rel
元素中的a
属性定位表单,而不是<form action="dilemman.php" method="post" class="copy"
元素。
<a href="#" class="copy" rel=".form">Duplicate form</a>
<form action="dilemman.php" method="post"
更改为
class="form"
的 <a href="#" class="copy" rel=".form">Duplicate form</a>
强>
#include <boost/program_options.hpp>
// ...
using namespace cv;
using namespace std;
namespace po = boost::program_options;
int signModule(int argc, char** argv);
int kfModule(int argc, char** argv);
int main(int argc, char** argv)
{
string helpText = "You need to specify a module:\n\tprogram [sign|kf]\n\nUse program <module> --help for a description.";
if (argc < 2) { // Then no module was given
cout << helpText << endl;
return -1;
}
string module = argv[1]; // This is the first argument. Index 0 holds the executable
// Copy argv but exclude argv[1}
int moduleArgC = argc -1;
char* moduleArgV[moduleArgC];
moduleArgV[0] = argv[0];
for(int i=1; i < moduleArgC ;++i) {
moduleArgV[i] = argv[i+1];
}
if (module == "sign")
return signModule(moduleArgC, moduleArgV);
else if (module == "kf")
return kfModule(moduleArgC, moduleArgV);
else { // default
cout << "Unknown module: " << module << "\n\n" << helpText << endl;
return -1;
}
}
int signModule(int argc, char** argv) {
try {
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("circle,c", po::value<string>(&recognizer::circleClassifierFilePath)->default_value(recognizer::circleClassifierFilePath), "Path to CircleClassifier")
("triangleUp,t", po::value<string>(&recognizer::triangleClassifierFilePath)->default_value(recognizer::triangleClassifierFilePath), "Path to TriangleUpClassifier")
("winSize,w", po::value<int>()->default_value(recognizer::winSize.width), "WinSize of HOGDescriptor as int")
("createHog", po::bool_switch(&recognizer::createHogFeaturesFromImages)->default_value(recognizer::createHogFeaturesFromImages), "Specifies if HOG features will be created even if HOG file is present.")
("svmKernel", po::value<int>(&recognizer::svmKernel)->default_value(recognizer::svmKernel), "The SVM kernel of the classifiers. LINEAR =0, POLY =1, RBF =2, SIGMOID =3, CHI2 =4, INTER =5")
("degree", po::value<double>(&recognizer::degreeOfPolyKernel)->default_value(recognizer::degreeOfPolyKernel), "The degree for the polynomial SVM kernel. Makes only sense with option --svmKernel=1 (POLY).")
;
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
options(desc).run(), vm);
po::notify(vm);
if (vm.count("help")) {
cout << "Usage: program [options]\n";
cout << desc;
return 0;
}
// Validate options
if (vm.count("winSize"))
{
int winSize = vm["winSize"].as<int>();
recognizer::winSize = Size(winSize, winSize);
}
if (vm["svmKernel"].as<int>() < 0 || 5 < vm["svmKernel"].as<int>()) {
cout << "Wrong svmKernel:\t" << vm["svmKernel"].as<int>() << "\tAllowed values: LINEAR =0, POLY =1, RBF =2, SIGMOID =3, CHI2 =4, INTER =5" << endl;
return 1;
}
}
catch(std::exception& e)
{
cout << e.what() << "\n";
return 1;
}
SignClassifier::createClassifier();
return 0;
}
int kfModule(int argc, char** argv) {
// Another module with different options
// ...
return 0;
}