简体   繁体   English

创建可在5月网站上访问的HTML弹出表单

[英]Creating an HTML popup form that is accessible on may websites

I want to have a HTML form that has two input textboxes and a submit button that can be places on many websites that I have. 我想要一个具有两个输入文本框和一个提交按钮的HTML表单,该按钮可以放置在我拥有的许多网站上。 I just want to have the reference to this form in the form of javascript code that takes some customizing arguments depending on which the form's shape, size or color should change. 我只是想以javascript代码的形式引用此表单,该代码需要一些自定义参数,具体取决于表单的形状,大小或颜色应更改。

I had already created a form ready with me that takes inputs and I want to make it as plug-in or some other kind of javascript code which when pasted on the other websites should pull out the form that I've created. 我已经创建了一个带有输入的表单,我想将其作为插件或其他某种javascript代码粘贴到其他网站上时,应提取出我创建的表单。

As you said, you must create a plugin. 如您所说,您必须创建一个插件。 You can write it in a separated file like insertMyForm.js . 您可以将其写入一个单独的文件中,例如insertMyForm.js

The plugin can be called with a specified div element that will be the parent of your form (for instance) 可以使用指定的div元素调用该插件,该元素将是表单的父级(例如)

(function($) {
    $.fn.insertMyForm = function(params) { 
        //check that parent ( $(this) ) is a div, or something else...
        //create your html element  
        var myFirstInput = $("<input>");//... 
        var myForm = $("<form>");//...
        //do some stuff with with your elements (css, handlers...)
        //append you form to the parent 
        $(this).append(myForm);//...
        //return something like the jQuery object of your form (return myForm;)
    };
})(jQuery);

Now in you page, in the script section, include insertMyForm.js and create your form : 现在,在您页面的脚本部分中,包含insertMyForm.js并创建您的表单:

$("#myParentElement).insertMyForm(params);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM