如果有人试图将部分产品添加到购物篮中该怎么办?
例如,如果一位顾客“愚蠢”(这里是礼貌的),尝试将 4.6 件商品添加到他们的购物篮中,您会期望看到什么? 或者你会如何处理它。 显然,我们只处理数字量(我们的钢锯上周坏了)。
网上似乎有很多不一致的地方。
- Amazon 向下舍入 (4.6->4, 1.3->1)
- FireBox 舍入 (4.6->5, 1.3->1)
- Ebuyer 忽略输入(无错误)
- Expansys 从您的购物篮中删除该商品
- 我假设 某些网站会显示错误
哪个是最好的解决方案
If a customer were "silly" (being polite here) enough to try and add, as an example, 4.6 items to their basket, what would you expect to see? or how would you deal with it. Obviously, we only deal with digital quantities (our hacksaw broke last week).
There seems to be a lot of inconsistence across the web.
- Amazon Rounds down (4.6->4, 1.3->1)
- FireBox Rounds (4.6->5, 1.3->1)
- Ebuyer ignores the input (no error)
- Expansys removes the item from your basket
- I'm assuming some site will show an error
Which is the best solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
嗯,你绝对不应该四舍五入。 无论客户的要求多么愚蠢,您都不应该收取比客户要求更多的材料。
Well, you definitely should never round up. You should not ever bill for more materials than the customer requested, no matter how inane the request.
在我看来,如果您的产品是一个购物系统,那么主要目标是销售一些商品是有道理的。 通常客户希望执行尽可能少的操作,因此系统应该预测客户在输入错误的输入时可能想要什么。
我将实施亚马逊加上通知用户输入不完全清楚并要求他重新检查该值。 因此,如果系统猜对了,那么用户不需要进行任何更改,但如果他输入错误,他会立即看到它。
您还可以记录所有此类事件,然后进行分析,了解用户第一次输入的内容以及他购买的实际数量。 只是为了好奇...
In my opinion if your product is an shopping system then it makes sense that primary goal is to sell some items. Usually customers want to perform as less actions as possible, so the system should predict what customer could possibly want when typing incorrect inputs.
I would implemented as Amazon plus informing user that input was not fully clear and asking him to recheck the value. So if the system guessed right then user need to change nothing but if he mistyped he'll see it immediately.
Also you could log all this kind of incidents and then perform an analysis, what user typed for the first time and what was the actual count he bought. Just for curiosity...
添加 JavaScript 验证,在用户输入时删除非数字输入
针对 JavaScript 时的情况实施向后解决方案关闭时,要么显示错误消息,要么对值进行四舍五入,但随后显示一条消息,指出“您的输入已调整”
添加:另请注意,分隔小数部分与整数部分的字符因国家/地区而异。 在美国我相信它是“.”,在欧洲它通常是“,”。 如果您的应用程序针对具有不同数字表示形式的不同国家/地区的客户,那么在应用程序逻辑中实现对这两种字符的支持是有意义的。 否则,一些用户将收到格式错误消息而不知道原因 - 非技术人员通常不知道此格式问题。
Add JavaScript verification that would remove non-numeric input while the user is typing in
Implement backward solution for the situation when JavaScript is off, either display an error message or round the value but then display a message saying "your input has been adjusted"
ADDED: Also be aware that the character that separates the fractional part from the integer one differs from country to country. In US I believe it is '.', in Europe it is usually ','. If your applications is targeted at customers in different countries with varying number representation, it would make sense to implement the support for both characters in your application logic. Otherwise some users will get format error messages without knowing why - non-techie people are often unaware of this format issue.
验证用户输入并仅接受数字字符怎么样?
How about validating the user input and accepting only numeric characters?
一种解决方案是提醒用户注意错误的输入,以便他们可以纠正。 根据上下文,四舍五入可能是一个过多的假设。
在金额旁边显示一条错误消息,如下所示:“抱歉,我们无法向您提供 4.6 件商品。请输入整数。” ...或类似的规定。
另一种解决方案是通过限制输入字段仅允许有效输入来避免显示错误消息。 即如果您不想要 4.6 项...仅允许用户能够键入 0-9。 如果用户无法输入错误的内容,那么就没有任何理由显示错误消息。
One solution would be to bring the incorrect input to the user's attention so they can correct it. Rounding can be too much of an assumption depending on the context.
Displaying an error message next to the amount something like this: "I'm sorry, we cannot supply you with 4.6 items. Please enter a whole number." ...or something along those lines.
Another solution would be to avoid displaying error messages by restricting the input field to only allow valid input. ie If you don't want 4.6 items...only allow the user to be able to type 0-9. If the user can't enter incorrect input then there is never any reason to display an error message.
假设您在这里讨论的是网络应用程序,您可以限制输入框中允许的字符。
或者,IMO 您可以使用微调器 (+/-) 控件来更改数量。
我相信tesco.com 就是这么做的。
Assuming you're talking about a web app here, you can limit the characters allowed in the input box.
Alternatively, IMO you could use spinner (+/-) controls to change the quantity.
I believe tesco.com does this.
根据我的观点,最好的解决方案是
The best solution according to me would be
一种解决方案是,当用户关闭允许输入分数的编辑字段时,通知用户他们的选择无效。
一个较小的选择是四舍五入(向下舍入,除非您贪婪地出售 1 件额外的物品),或者完全拒绝输入。
最好的解决方案是首先通过为分数提供滑块或旋转控件以仅选择整数来防止分数。
One solution would be to inform the user that their selection is invalid when they tab off the edit field that's allowed them to enter the fraction.
A lesser option would be to round (down, unless you're greedy to sell 1 extra item), or to reject the input completely.
The best solution is to prevent fractions in the first place by giving them a slider or spin control to select only whole numbers.
最后添加服务器端检查总是更安全。
因此,如果输入不是整数值:
At the end it's always safer add server side check.
So if the input it's not an integer value: