小编Mor*_*ost的帖子

iOS Safari:默认验证气泡消息未正确对齐

我们正在使用 HTML5 表单验证,而不会覆盖验证错误消息的默认系统 UI。这在任何地方都可以正常工作,但在 iOS Safari 上,验证消息在气泡弹出窗口中没有正确对齐。我们已经在两个完全独立的设备上以不同的形式对此进行了测试。即使是没有 CSS 的最小表单也有相同的结果:

https://jsfiddle.net/GinSan/48hnrf92/1/

<form>
  <label for="test">Test field</label>
  <input required id="test" name="test" type="text">
  <button type="submit">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)

这是我们测试的 iOS 设备上的验证消息:

iPhone 上的英文验证消息

iPad 上的德语验证消息

验证消息与顶部对齐而不是居中,即使这是一个系统 UI 元素。这是一个已知问题吗?除了向苹果报告并等待修复或更换系统验证消息之外,还有什么可以做的吗?

html mobile-safari ios constraint-validation

13
推荐指数
1
解决办法
954
查看次数

随机返回三个选项之一的函数,其中所有选项都具有完全相同的机会?

我知道之前可能已经问过这个问题,但我正在尝试使用Javascript函数返回三个选项之一.问题是每个选项应该完全相等的机会.这是我到目前为止:

var choice = Math.random();
if (choice <= 0.34) {
    choice = "option1";
} else if (choice <= 0.67) {
    choice = "option2";
} else {
    choice = "option3";
}
Run Code Online (Sandbox Code Playgroud)

这已经非常准确,但"option3"的概率略低.如何重新制定这个以使每个选项都有相同的发生机会?我更喜欢一种不涉及在if条件或类似情况下使用"0.3333333333333333 ..."的解决方案.

javascript random

1
推荐指数
1
解决办法
67
查看次数

windows.print 导致空页

所以我正在尝试向 html 页面添加一个打印按钮。大部分页面不应该出现在打​​印中,所以我隐藏了打印中的所有内容,然后只显示应该打印的一个 div(或者这就是我想要做的)。但是当我尝试打印按钮时,结果页面完全是空的。页面的 html 结构如下所示:

<body>    
<div id="fullpage">

    <div class="section">
    some stuff that should not be printed
    </div>
    <div class="section">
    even more stuff that should not be printed
    </div>

    <div class="section" id="results_page">
        <img id="result_image" class="archiv" src="./images/heumarkt/APDC0013.JPG">

        <div class="content_wrapper" id="result_text">
            <h1 id="result_h1">some stuff</h1>
            <h2 id="result_h2">more headlines</h2>
            <p id="result_p1">some text</p>
            <button class="print_trigger" onclick="javascript:print_stadtarchiv(true)">print</button>
            <button class="print_trigger" onclick="javascript:print_stadtarchiv(false)">print without picture</button>
        </div>
    </div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)

这是应该隐藏除 id 为“results_page”的 div 之外的所有内容的 CSS(当然,该 div 中的按钮也应该在打印时隐藏)。

@media print {
*{
    background-color:transparent;
}
div#fullpage .section, .print_trigger, .unprintable{
    display:none; …
Run Code Online (Sandbox Code Playgroud)

javascript css printing

1
推荐指数
1
解决办法
1万
查看次数