0

我想在其中使用文本笔划<input type="text"/>,我需要它是跨浏览器(firefox、google chrome、safari、opera、IE7+)。

有什么方法可以做到(CSS 2.1,jQuery ...)?

4

4 回答 4

4

我相信他说的是 CSS 属性 text-stroke ( -webkit-text-stroke)。这仅在 webkit 浏览器中得到适当支持,因此无法在 Internet Explorer 等中正确实现。但是,您可以假装它text-shadow可以在 ie7+ 中使用。如果你必须把它放进去。请参阅http://css-tricks.com/adding-stroke-to-web-text/

它看起来像:

.stroke_text {
    color: white;
    text-shadow:
          -1px -1px 0 #000,
          1px -1px 0 #000,
          -1px 1px 0 #000,
          1px 1px 0 #000;
}

或内联:

<input type='text' 
       style="color: white; text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; width:200px; font-size:20px;" />

这种方法唯一真正的缺点是阴影只能是 1px 或者它开始看起来很有趣,所以它不是text-stroke. 也就是说,您可能想研究条件 css,支持它的浏览器使用 text-stroke,而其他浏览器则使用这种 hacky 方法。

于 2012-02-09T14:57:57.657 回答
0

我不完全确定你的意思,但我认为这就是你想要的 -

<input type="text" onkeyup="function_you_want_tocall()" />
于 2012-02-09T14:55:57.173 回答
0

使用 jQuery,您可以执行以下操作:

$(document).ready(function() {
    $("input[type='text']").keypress(function() {
        // Your logc goes here
    });
});

这会将按键事件绑定到每个输入类型 = 文本。如果您想要一个特定的 ID,请将 $("input[type='text'] 替换为 $("#your_id")。此外,还可以使用 keydown 和 keyup 事件来找出最适合您的 ID。

于 2012-02-09T14:57:51.403 回答
0

由于这个模糊的问题,你有很多选择:

$('#myInput').change(function() { ... } ); // this will fire onblur if the text has changed
$('#myInput').keydown(function() { ... } ); // this will fire when a key is pressed down
$('#myInput').keyup(function() { ... } ); // this will fire when a key is released
$('#myInput').keypress(function() { ... } ); // this will fire when a printable key is pressed
于 2012-02-09T14:56:53.543 回答