让AI用原生HTML+CSS+JavaScript编写一个可直接在浏览器打开使用的在线投票程序,支持创建投票、实时计票、防重复投票、数据持久化与重置等功能,代码单文件、无依赖,适合轻量投票工具开发。

中文版提示词

你是一名资深网页前端开发工程师,请使用原生HTML+CSS+JavaScript编写一个可直接在浏览器中打开使用的在线投票程序,要求如下:

功能:
- 创建投票:输入投票标题,至少含2个选项,支持添加/删除选项;
- 开始投票:显示选项列表,点击为某一选项投票,实时更新票数与百分比;
- 防重复投票:同一设备对同一投票仅能投一次(使用localStorage记录);
- 结果展示:显示每个选项的票数与百分比,提供简单进度条或条形图效果;
- 数据持久化:投票标题、选项、票数、是否已投状态均使用localStorage保存,刷新后保留;
- 重置:提供"重置投票"按钮,清空数据并重新创建投票。

界面与技术:
- 风格简洁淡雅(浅灰/浅蓝),居中卡片布局,按钮圆角加阴影;
- 使用CSS Flex或Grid布局,当前日期不需要显示;
- 不使用任何框架或库,全部代码在同一个HTML文件中;
- 使用原生JavaScript操作DOM,逻辑清晰,适量注释。

输出格式:直接保存为vote.html文件,在浏览器中打开即可使用,代码可直接运行,无需任何依赖。

英文版提示词

You are a senior front-end developer. Use vanilla HTML + CSS + JavaScript to build an "online voting app" that runs directly in the browser, with these requirements:

Features:
- Create a poll: enter a poll title with at least 2 options, and support adding/removing options;
- Start voting: show the option list, let users click an option to vote, and update vote counts and percentages in real time;
- Prevent duplicate voting: the same device can vote only once per poll (track this with localStorage);
- Results display: show each option's vote count and percentage with a simple progress bar or bar-chart effect;
- Data persistence: poll title, options, vote counts, and voted status are all stored in localStorage and preserved after refresh;
- Reset: provide a "Reset poll" button to clear data and create a new poll.

UI and tech:
- A clean, light style (light gray/blue), centered card layout, rounded buttons with shadows;
- Use CSS Flex or Grid layout; no need to display the current date;
- Use no frameworks or libraries — all code in a single HTML file;
- Use vanilla JavaScript to manipulate the DOM, with clear logic and appropriate comments.

Output format: save it directly as vote.html and open it in the browser; the code must run directly with no dependencies.

🛠️ **适用 AI 工具**:Claude、ChatGPT、Cursor、Copilot、DeepSeek、Gemini