我想使用jquery validate插件验证表单,但是我无法在html中使用'name'值 - 因为这是服务器应用程序也使用的字段.具体来说,我需要限制从组中检查的复选框的数量.(最多3个.)我看过的所有例子都使用每个元素的name属性.我想要做的是改用类,然后为此声明一个规则.
HTML
这有效:
<input class="checkBox" type="checkbox" id="i0000zxthy" name="salutation" value="1" />
Run Code Online (Sandbox Code Playgroud)
这不起作用,但是我的目标是:
<input class="checkBox" type="checkbox" id="i0000zxthy" name="i0000zxthy" value="1" />
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
var validator = $(".formToValidate").validate({
rules:{
"salutation":{
required:true,
},
"checkBox":{
required:true,
minlength:3 }
}
});
Run Code Online (Sandbox Code Playgroud)
是否可以这样做 - 有没有一种方法可以在规则选项中定位类而不是名称?或者我是否必须添加自定义方法?
干杯,马特
我很难在对象方法中的javascript内联函数中引用"this".
var testObject = {
oThis : this,
testVariable : "somestring",
init : function(){
console.log(this.testVariable); // outputs testVariable as expected
this.testObject.submit(function(){
var anotherThis = this;
console.log(this.testVariable) // undefined
console.log(oThis.testVariable) // undefined
console.log(testObject.testVariable) // outputs testVariable
console.log(anotherThis.testVariable) // undefined
}
}
Run Code Online (Sandbox Code Playgroud)
如何this.testVariable从提交功能中进行访问?我也使用jQuery,如果这有所不同.
我想知道这是否是最好的方法 - 也许我应该作为一个单独的函数提交,然后引用内联,如:
init : function(){
this.testObject.submit = this.submitForm;
},
submitForm : function(){
// do validation here
console.log(this.testVariable) // outputs testvariable
.
.
.
return valid;
}
Run Code Online (Sandbox Code Playgroud)
但这似乎也没有用 - 我想我现在只想在我的init方法中保持提交函数内联.
我能够在网页中嵌入并设置字体样式,以便在Android和iPhone上查看,并且工作正常.但是,它不会在Windows Phone 7.5上呈现.
我已经尝试将字体嵌入到CSS中:
@font-face {
font-family:'MyFont';
src: url(data:font/woff;charset=utf-8;base64,d09GR...
}
Run Code Online (Sandbox Code Playgroud)
...还提供了eot/ttf文件,使用适用于所有其他浏览器的声明 -
@font-face {font-family:'MyFont';src:url('../fonts/MyFont-webfont.eot');src:url('../fonts/MyFont-webfont.eot?#iefix') format('embedded-opentype'), url('../fonts/MyFont-webfont.svg#MyFontRegular') format('svg'), url('../fonts/MyFont-webfont.woff')format('woff'), url('../fonts/MyFont-webfont.ttf') format('truetype');font-weight:normal;font-style:normal;}
Run Code Online (Sandbox Code Playgroud)
......但仍然没有运气.我无法相信新的Windows手机不允许字体嵌入,只支持有限的字体列表,如下所述:
http://msdn.microsoft.com/en-us/library/hh202920%28v=vs.92%29.aspx
即使它是一个Javascript渲染解决方案,任何见解/提示或提示都会很棒......必须有某种解决方法!