问题自定义<输入类型=“搜索" ...> jQuery Mobile [英] Problem Customize <input type="search" ...> Jquery Mobile

查看:112
本文介绍了问题自定义<输入类型=“搜索" ...> jQuery Mobile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在ID为搜索"的文件中显示消息搜索",并在用户单击时使其消失.这是我的代码.这是行不通的.

I want to show the message "search" in the filed with an id of "search" and have it disappear when the user clicks. Here is my code. It doesn't work.

 <script>
 $('#acceuil').live('pagecreate',function(event){
 $('#search').blur(function(){
    if ($('#search').val()=='')
    $('#search').val("search");
});

$('#search').focus(function(){
    if (('#search').val()=='search')
    $('#search').val("");
});
});
</script>



<div data-role="page" id ="acceuil" >
<div data-role="header" data-theme="a" ><h3>TEST</h3></div>
<div data-role="content">
   <div data-role="container" >
    <img src="images/olampromo.gif">
</div>
<div data-role="container">
    <label for="search">Cherchez votre coupon :</label>
    <input type="search" id="search" value="search">        
</div>

</div>
<div data-role="footer" data-theme="a" ><h3>footer</h3></div>

推荐答案

您错过了JS中的$.尝试更改行:

You missed a $ in your JS. Try changing the line:

if (('#search').val()=='search')

收件人:

if ($('#search').val()=='search')

您可以通过使用this进一步改进它. this将引用触发事件的对象(即搜索元素).因此,请尝试:

You could further improve it by making use of this. this will refer to the object that the event was triggered on (i.e. the search element). So, try instead:

if ($(this).val()=='search')

相同的逻辑适用于模糊处理程序和焦点处理程序.

The same logic applies to both the blur and focus handlers.

这是 jsFiddle 展示的解决方案.

这篇关于问题自定义&lt;输入类型=“搜索" ...&gt; jQuery Mobile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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