简体   繁体   English

无法更改以验证

[英]Cant get onchange to Validate

Hey I'm using the onchange attribute or we they are called, and it wont vailidate in XHTML 1.0 Strict when using the w3c validater which i have to use, i need a way around this so that my code will still work, and validate. 嘿,我在使用onchange属性或我们称之为onchange属性,并且在使用我必须使用的w3c验证程序时,它不会在XHTML 1.0 Strict中生效,我需要一种解决方法,以便我的代码仍然可以正常工作并进行验证。 the error is: Line 211, Column 32: there is no attribute "onchange" 错误是:第211行,第32列:没有属性“ onchange”

and here are the values it effects or w/e (not in proper order just cut and pasted) 这是它影响或w / e的值(剪切和粘贴的顺序不正确)

Cost of Registration:<input id="cost" name="cost" readonly="readonly"/>
<p>
<input type="checkbox" id="monday" name="Attending" value="monday" />Monday<br />
<input type="checkbox" id="tuesday" name="Attending" value="tuesday" />Tuesday<br />
<input type="checkbox" id="wesnesday" name="Attending"value="wednesday"/>Wesnesday<b/></p>

i have another onchange that the validater seems to have no problems with 我有另一个onchange,验证者似乎没有问题

<p>
 <select id="regcat" onchange="autofill()">
 <option value="UWS Student">UWS Student</option>
 <option value="Student at another institution">Student at another institution</option>
 <option value="UWS Academic">UWS Academic</option>
 <option value="Other UWS Staff">Other UWS Staff</option>
 <option value="Academic from another Institution">Academic from another   Institution</option>
 <option value="Professional">Professional</option>
 <option value="Retired">Retired</option>
</select>
</p>

Can find a fix for this anywhere.(sorry for grammar and spelling its very late) 可以在任何地方找到解决方法。(对不起,语法拼写太晚了)

You need to attach your event handler through JavaScript instead of the attribute. 您需要通过JavaScript而非属性附加事件处理程序。 If you're using jQuery: 如果您使用的是jQuery:

$('#regcat').change(autofill);

You'll want this in a document ready wrapper if you're not already using one. 如果您还没有使用过这种包装,则需要在准备好文档的包装中使用。 The shortest way: 最短的方法:

$(function() {
    $('#regcat').change(autofill);
});

If you're not using jQuery, you'll use the addEventListener method (but again, you'll need to account for the DOM being ready). 如果您不使用jQuery,则将使用addEventListener方法 (但同样,您需要考虑已准备就绪的DOM)。 If you're not using jQuery AND you need to support IE <9, you'll unfortunately have to also add in the attachEvent call within a conditional comment wrapper. 如果您不使用jQuery并且需要支持IE <9,那么不幸的是,您还必须在条件注释包装器中添加attachEvent调用。

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

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