简体   繁体   English

如何隐藏内容,但在点击时显示

[英]how to hide content, but show it on click

So I have this code:所以我有这个代码:

<script type="text/javascript">
$(document).ready(function() {
$('.rm_color').each(function() {
    var divPicker = $(this).find('.colorpicker');
    var inputPicker = $(this).find('input[type=text]');
    divPicker.hide();
    divPicker.click(function(){divPicker.farbtastic(inputPicker)});
    }); 
});
</script>

My intention was to hide the farbtastic feature, but when the use doubleclick the textarea input, the farbstastic feature shows up.我的意图是隐藏 farbtastic 功能,但是当使用双击 textarea 输入时,farbstastic 功能出现了。 And when user doubleclick it again, the farbstastic goes hidden.当用户再次双击它时,farbstastic 会隐藏起来。

How to crate the proper code using the above code?如何使用上面的代码创建正确的代码? Many thanks非常感谢

UPDATED: with the answer:更新:答案:

I've found the answer:我找到了答案:

<script type="text/javascript">
    $(document).ready(function() {
        $('.rm_color').each(function() {
            var divPicker = $(this).find('.colorpicker2');
            var inputPicker = $(this).find('input[type=text]');     
            divPicker.hide();
            divPicker.farbtastic(inputPicker);
            inputPicker.dblclick(function(){divPicker.slideToggle()});
        });
    });
</script>

Here's the modified code if you're taking the original declaration script from the farbtastic official website.如果您从 farbtastic 官方网站获取原始声明脚本,这是修改后的代码。

http://acko.net/dev/farbtastic http://acko.net/dev/farbtastic

<script type="text/javascript">
    $(document).ready(function() {
    $('#colorpicker4').hide();
    $('#colorpicker4').farbtastic('#color4');
        $('#color4').dblclick(function(){$('#colorpicker4').slideToggle()});
     });
</script>

http://api.jquery.com/dblclick/ http://api.jquery.com/dblclick/

<script type="text/javascript">
var isOpen = false;
$(document).ready(function() {
$('.rm_color').each(function() {
    var divPicker = $(this).find('.colorpicker');
    var inputPicker = $(this).find('input[type=text]');
    divPicker.hide();
    divPicker.dblclick(function(){
if(isOpen){
//close
isOpen = false;
}else{
divPicker.farbtastic(inputPicker)
isOpen = true;
}
});
    }); 
});
</script>

Try this尝试这个

<script type="text/javascript">
$(document).ready(function() {
$('.rm_color').each(function() {
    var divPicker = $(this).find('.colorpicker');
    var inputPicker = $(this).find('input[type=text]');
     divPicker.hide();
     inputPicker.dbclick(function(){ divPicker.toggle(); if(divPicker.is(":visible")){                  
       divPicker.farbtastic(inputPicker);}
     });
    }); 
});
</script>

I've found the answer:我找到了答案:

<script type="text/javascript">
    $(document).ready(function() {
        $('.rm_color').each(function() {
            var divPicker = $(this).find('.colorpicker2');
            var inputPicker = $(this).find('input[type=text]');     
            divPicker.hide();
            divPicker.farbtastic(inputPicker);
            inputPicker.dblclick(function(){divPicker.slideToggle()});
        });
    });
</script>

Here's the modified code if you're taking the original declaration script from the farbtastic official website.如果您从 farbtastic 官方网站获取原始声明脚本,这是修改后的代码。

http://acko.net/dev/farbtastic http://acko.net/dev/farbtastic

<script type="text/javascript">
    $(document).ready(function() {
    $('#colorpicker4').hide();
    $('#colorpicker4').farbtastic('#color4');
        $('#color4').dblclick(function(){$('#colorpicker4').slideToggle()});
     });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM