x-webkit-speech:onwebkitspeechchange不会重置该值 [英] x-webkit-speech: onwebkitspeechchange is not reseting the value

查看:102
本文介绍了x-webkit-speech:onwebkitspeechchange不会重置该值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用onwebkitspeechchange事件重置输入值,以便仅保留语音文本.

I'm trying to reset my input value with onwebkitspeechchange event so that only speech text remains in value.

onclick删除了文字

点击对话框后弹出,并将值重置为初始文本

after click dialog pop up and value reset to initial text

代码:

<input name="s" type="text" x-webkit-speech="" id="s" value="What are you looking for?" onfocus="if (this.value == 'What are you looking for?') {this.value = '';}" onwebkitspeechchange="if (this.value == 'What are you looking for?') {this.value = '';}" onblur="if (this.value == '') {this.value = 'What are you looking for?';}">

我知道onblur事件正在执行此操作,但是如何为onwebkitspeechchange设置例外,以便仅保留语音?

I know that onblur event is doing this but how can I make an exception for onwebkitspeechchange so only speech reamain?

不能使用占位符属性(在ie 9中无效)

can't use placeholder attribute (doesn't work in ie 9)

推荐答案

我遇到了相同的问题,并使其与简单的JS函数一起使用.这是我的解决方案:

I ran into the same problem and got it working with a simple JS function. Here's my solution:

<input x-webkit-speech="x-webkit-speech" onwebkitspeechchange="webkitSpeechChange(this);" name="myinput" value="<?php echo $this->__('Search entire store here...') ?>" class="search-query" />
<script type="text/javascript">
    //<![CDATA[
    function webkitSpeechChange(input) {
        input.value = input.value.replace('<?php echo $this->__('Search entire store here...') ?>', '');
    }
    //]]>
</script>

其中<?php echo $this->__('Search entire store here...') ?>应该是您的默认值.

where <?php echo $this->__('Search entire store here...') ?> should be your default value.

希望这会有所帮助:)

这篇关于x-webkit-speech:onwebkitspeechchange不会重置该值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆