We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
实现一个模拟的下拉表单控件:Select。功能要求如下:
说明:
text
setValue
value
select[id=rel]
小提示:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <link rel="stylesheet" href="index.css" /> </head> <body> <h2 id="info"></h2> <div id="sex-select"></div> <div id="career-select"></div> <select id="rel"> <option value="1">男</option> <option value="0">女</option> </select> <script src="Select.js"></script> <script> var sexOptions = [ {text: 'male', value: 1}, {text: 'female', value: 0} ]; var careerOptions = [ {text: 'ue', value: 1}, {text: 'fe', value: 2}, {text: 'rd', value: 3}, {text: 'qa', value: 4}, {text: 'op', value: 5}, {text: 'pm', value: 6} ]; var sexSelect = new Select( sexOptions, document.getElementById('sex-select') ); var careerSelect = new Select( careerOptions, document.getElementById('career-select') ); sexSelect.render(); careerSelect.render(); sexSelect.onchange = careerSelect.onchange = function () { document.getElementById('info').innerHTML = sexSelect.getValue() + ',' + careerSelect.getValue(); }; document.getElementById('rel').onchange = function () { sexSelect.setValue(this.value); }; </script> </body> </html>
function Select(options, main) { // 实现Select组件的构造函数 // 在这里初始化一些信息 this.options = options || []; this.main = main; // ...... } Select.prototype.render = function () { // 实现Select组件的渲染 // 在这里创建select相关的dom,append到页面中,并绑定相关行为 }; Select.prototype.setValue = function (value) { // 实现setValue方法,使JS能够更改Select当前选中的值 }; Select.prototype.getValue = function () { // 实现setValue方法,使JS能够获取Select当前选中的值 };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
实现一个模拟的下拉表单控件:Select。功能要求如下:
说明:
text
属性的内容;使用setValue
方法设置值时,通过value
属性对应select[id=rel]
的原始表单,要求其选择的变化能实时同步到模拟的sexSelect中。select[id=rel]
的事件在参考代码中已经绑定好,只要正确实现setValue
方法就能做到小提示:
参考 index.html 代码
参考 Select.js 代码
The text was updated successfully, but these errors were encountered: