首页 > 其他分享 >qForms tips

qForms tips

时间:2023-07-20 18:36:10浏览次数:34  
标签:form 代码 qForm qForms value input tips formName

官方教程

http://www.pengoworks.com/qforms/docs/index.htm

1 set和get form 中的field的代码

本来obj.fieldName.getValue() 可以用来获取form中某个field的值,


用obj.fieldName.setValue() 可以用来设置form中某个field的值。





js为:




function  testqForm()
 {

alert( wfqForm.texttest.getValue());
alert(wfqForm.selradio.getValue() );

}

上面的代码是从form的field着眼来写的。


现在从form着眼来写。


利用


obj.setFields(object struct, [boolean resetDefault], [boolean resetAll]) 和 obj.getFields() (obj代表的是一个qForm对象) 下面的代码来自qforms官方的例子:

http://www.pengoworks.com/qforms/docs/examples/setfields.htm

(设置了几个fields:Name,Email,EmailUpdates, FavoriteActivities)

function  populate() {
76 // create the associative array
77 stcForm = new Object();
78 // populate the array with the form fields as the key,
79 // and the value for the fields as the value
80 stcForm.Name = "Dan G. Switzer, II";
81 stcForm.Email = "[email protected]";
82 stcForm.EmailUpdates = "1";
83 // since no values is given, no value will be selected
84 stcForm.FavoriteActivities = "Reading,Music,Sports";
85
86 // populate the form
87 objForm.setFields(stcForm);
88}

读取上面几个fields的value

function showForm()...{
91 // if all you want to do is display the content of the form in an alert
92 // box for debugging information, use the objForm.dump() method instead.
93 // this will do the exact same thing as this function.
94 var str = "";
95 struct = objForm.getFields();
96 for( key in struct ) str += key + " = " + struct[key] + " ";
97 alert(str);
98}



2 在ie和firefox中使用时遇到的一个问题


注意到,对一个名为formName的form

如果使用如下代码来创建qForm对象的话,在firefox中可以使用,而在ie中不行。

formName = new qForm("formName");

据揣测:

ie中无法区别名为formName的form和名为formName的qForm对象,

而在firefox中确可以。


所以,这种写法不规范。

建议;

formNameObj = new qForm("formName");



3 在form中设置required的field。

< SCRIPT  LANGUAGE ="JavaScript" >
<!--//
// initialize the qForm object, specify the layer(document.singleChoice) in which the form resided in
wfqFormObj = new qForm("wfqForm", "document.singleChoice");
wfqFormObj._locked = true;

wfqFormObj.required('field1, field2,field3');

//-->
 </ SCRIPT >


4 似乎qForm._locked = true似乎对button类型无用

5 使用innerHTML时遇到的问题


下面的form用另一个form来代替


并且新form也有就form有的input


并且新旧form的名字都一样。


< div >
 < form  name ="wfqListForm" >
 < input  type ="text"  name ="a"  value ="a" />
                
 < SCRIPT  LANGUAGE ="JavaScript" >
<!--//
// initialize the qForm object, specify the layer(document.singleChoice) in which the form resided in
wfqListFormObj = new qForm("wfqListForm");
//-->
 </ SCRIPT >
 </ form >
 </ div >




用来替换的form

< form  name ="wfqListForm" >
 < input  type ="text"  name ="a"  value ="a" />
                
 < SCRIPT  LANGUAGE ="JavaScript" >
<!--//
// initialize the qForm object, specify the layer(document.singleChoice) in which the form resided in
wfqListFormObj = new qForm("wfqListForm");
//-->
 </ SCRIPT >
 </ form >


替换代码js:


div.innerHTML = .....//新form(上面)的代码

问题是:


新form中虽然有script,但是script并没有被调用。


因此,js代码执行之后dom中wfqListFormObj还是代码原来的form。


但是原form已经不存在,被替换了。所以指向原form的wfqListFormObj中的对象的指向是有问题的。


比如wfqListFormObj中的input还是指向原form中的input,而不是现form中的input。


现form并没有相应的qForms对象。


因此替换js代码要加一行,显示为新form创建qForms对象,如下:


div.innerHTML  =  ..... // 新form(上面)的代码
 wfqListFormObj  =   new  qForm( " wfqListForm " );
这样,dom中才有了与现form对应的qForms对象。

 

                                <input type="radio" name="selradio" value="1" >
<input type="radio" name="selradio" value="2" >
            <input type="radio" name="selradio" value="3" >
            <input type="text" name="texttest" value="ddd" >
            <input type="button" onClick="testqForm();" value="testqForm" >
div.innerHTML  =  ..... // 新form(上面)的代码
 wfqListFormObj  =   new  qForm( " wfqListForm " );
这样,dom中才有了与现form对应的qForms对象。

 

                                <input type="radio" name="selradio" value="1" >
<input type="radio" name="selradio" value="2" >
            <input type="radio" name="selradio" value="3" >
            <input type="text" name="texttest" value="ddd" >
            <input type="button" onClick="testqForm();" value="testqForm" >

标签:form,代码,qForm,qForms,value,input,tips,formName
From: https://blog.51cto.com/u_11326739/6789688

相关文章

  • nginx反代配置tips
    nginx轮训导致验证码不正确在upstream里添加ip_hash;,例子:http{upstreamtest{#这样同一台电脑会一直访问到同一台机器ip_hash;server172.0.0.1:8080;}}静态资源访问出错在location里重写header:server{location/{......
  • 【Tips】克隆网站为单个HTML文件、将一个完整的页面保存到单个 HTML 文件中
    ProjectonGitHub:https://github.com/gildas-lormeau/SingleFileChrome插件市场https://chrome.google.com/webstore/detail/singlefile/mpiodijhokgodhhofbcjdecpffjipkle ......
  • Tips
    周赛6B很大的某一段区间内查找内某种数的出现次数是,利用id[i],lower_bound和upper_bound.cnt(l,r)=upper_bound(id+1,id+1+n,r)-lower_bound(id+1,id+1+n,l)很多多个数涉及&,|,^的,常常把每个数拆分成二进制进而探讨规律。3.周考7B把序列转化为数字:要考虑每一位上是否有负数......
  • TIPS清洁和缩小毛孔
    清洁和缩小毛孔是许多人关注的美容问题。以下是一些常见的方法来清洁和缩小毛孔:清洁步骤:每天使用温和的洗面奶清洁脸部,特别注意T区(额头、鼻子和下巴)的清洁。避免使用过度刺激或含有硫酸盐的产品,因为它们可能使皮肤更干燥。定期去角质,以帮助去除死皮细胞和深层清洁毛孔。选择......
  • Xml Tips
    XmlTips1.xml中的注释<!--这是注释-->并非用于XML分析器的内容(例如与文档结构或编辑有关的说明)可以包含在注释中。注释以<!--开头,以-->结尾,例如<!--cataloglastupdated2000-11-01-->。注释可以出现在文档序言中,包括文档类型定义(DTD);......
  • Tips: How to Get the Currently Selected HTML Content in Major Browsers
    functiongetSelectionHtml(){constsel=window.getSelection();if(sel.rangeCount){varcontainer=document.createElement("div");for(vari=0,len=sel.rangeCount;i<len;++i){container.appendCh......
  • 小tips:docker 配置国内镜像地址
    在配置文件daemon.json中添加国内镜像,让其下载加速。vi/etc/docker/daemon.json如下国内镜像:{"registry-mirrors":["https://registry.docker-cn.com","http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn"]d......
  • DataTable DataRow String Tips...
       与datatable奋战了一天,记录一下。。。      1.查看得到的datatable是否为空datatable.Rows.Count   2.查看得到的DataRow[]是否为空,可用DataRow.Length   3.DataTable在进行select的时候,默认是CaseSensitive为false   4.......
  • python 列表 tips stackOverflow数据统计
    PYTHON笔记一Noteone**python中的集合类,有列表,元组,字典和集合四种。定义方式分别为:List=[]Turple=()Dict={key:value}Set={}作为JAVA程序员看来,python中的集合与JAVA中的集合类其实很相似,用着肯定是python更好用,个人认为优点如下:1.没有强定义类型。2.提供了很方便的......
  • 模型训练-tips
    模型冻结部分层的训练方式:第一步:在训练之前,将除了Embedding之外的层设置为param.requires_grad=False,如下所示:forname,paraminmodel.named_parameters():if"model.embed_tokens"notinname:param.requires_grad=False第二步:在训练的时候,在优化......