小编ste*_*Kim的帖子

MDL- componentHandler.upgradeDom(); 在ajax电话之后

我使用Google Material Design lite跟踪ajax设置:

first.php

<button class="rhm_add_button" type="button" >
    Show                      
</button>
<div class="rhm_add"></div>


<script>
jQuery(document).ready(function() {
            jQuery('.rhm_add_button').click(function(e) {
                e.preventDefault();
                jQuery.ajax({
                    type: "GET",
                    url: "<?php echo admin_url('admin-ajax.php'); ?>", 
                    dataType: 'html',
                    data: ({ action: 'rhmp_indi_form'}),
                    success: function(data){
                            jQuery('.rhm_add').html(data);
                },                  
                error: function(data)  
                {  
                alert("Error!");
                return false;
                }  
                }); 
         }); 
     }); 
</script>
Run Code Online (Sandbox Code Playgroud)

的functions.php

function rhmp_indi_form_callback() {  
    $template_part_path = 'page-parts/second_page';
    get_template_part($template_part_path);
    exit;
}
add_action('wp_ajax_rhmp_indi_form', 'rhmp_indi_form_callback');
add_action('wp_ajax_nopriv_rhmp_indi_form', 'rhmp_indi_form_callback');
Run Code Online (Sandbox Code Playgroud)

Second_file.php

 <div class="mdl-textfield mdl-js-textfield">                                       
    <input class="mdl-textfield__input" type="text" id="title" name="title"/>
    <label class="mdl-textfield__label" for="title">Name</label>                                        
 </div>
Run Code Online (Sandbox Code Playgroud)

如您所见,我正在使用MDL,当内容通过ajax加载时,它们无法正常工作,我从github找到了以下解决方案:https://github.com/google/material-design-lite/issues/1043

解决方案是我需要使用"componentHandler.upgradeDom();" …

php ajax material-design

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

如何相对于屏幕(视口)定位元素?

所以,我有一个位于页面右下角的按钮,如图所示(“当前”):

在此处输入图片说明

设置非常简单:

<div class="content">
    Content
</div>
<div class="button" style="position:absolute;right:0px;bottom:0px;">
    Button
</div>
Run Code Online (Sandbox Code Playgroud)

现在,有没有办法将按钮定位在“可见”屏幕底部而不是像“需要”图片所示的内容底部?

谢谢!

css php jquery

2
推荐指数
2
解决办法
1422
查看次数

jQuery 检查空变量

所以,我有以下 js 标记:

jQuery(document).on( 'click', '.rhpcon', function(e) {  
    var rhp_name = jQuery(this).find('.rhi').data("name");

    var my_html = '<div class="rhfi">'+ rhp_name +'</div>'; 
        my_html += '<div class="something">Show something else</div>';                          
    jQuery('.rh_pop').html(my_html);                        
});
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,该rhp_name变量在硬编码的 html 中使用。

然而,有些情况data-name不存在(即没有rhp_name变量)。

在没有rhp_name变量的情况下,我不想my_html使用第一行。

如何检查是否var为空等?

谢谢!

jquery

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

JS 检查 img 是否找不到

所以,我有以下 js img var。

//Where `img_src` is another variable which actual image file MIGHT or MIGHT NOT exist.
var img_source = "/images/" + img_src;   
return '<img  src="' + img_source + '">';    
Run Code Online (Sandbox Code Playgroud)

因为img_src可能可用也可能不可用,有时我会收到404 Not Found错误消息。

如果没有图像,那么我想执行另一个功能。

在这种情况下如何检查图像文件是否可用?

如果图像不可用,我试图避免将 img 属性一起显示。谢谢!

jquery image

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

CSS/JS 在动态 ul 中定位按钮

所以,我有一个下拉菜单,ulli结构如下:

<ul class="container"> 
    <span class="content_container"><!-- Empty --></span>
    <span class="fixed_area">Fixed Button</span>
</ul>
Run Code Online (Sandbox Code Playgroud)

然后在 JS 中,我简单地将动态附加licontent_container

$('span.content_container').html(li_content);
Run Code Online (Sandbox Code Playgroud)

给...

<ul class="container">
    <span class="content_container">
       <li>Something</li>
       <!-- and so on dynamically -->
    </span>
    <span class="fixed_area">Fixed Button</span>
</ul>
Run Code Online (Sandbox Code Playgroud)

我试图用一个按钮定位一个固定区域,如下图:

在此处输入图片说明

ul具有800像素的最大高度。当有很多 时lifixed_area按如下方式定位按钮相当简单:

span.fixed_area {
   height: 48px;
   width: 100%;
   position: fixed;
   background-color: red;
   top: 750px;
}
Run Code Online (Sandbox Code Playgroud)

我可以简单地将固定按钮定位到最大高度容器的底部。

问题:

问题是,由于我是li动态获取的,有时li加载不够,但固定按钮仍位于top:750px,因此通常不可见或放错位置。

我正在尝试做的事情:

我可以重新构建 html 部分。我需要将固定按钮始终放置在可见容器的底部,无论列表有多长,如图所示,A 和 B。

希望这是有道理的。

任何帮助都感激不尽!

html css jquery

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

php array_filter表示"False"值

array_filter在php中使用:

$new_array = array_filter($updated, "check_if_value_is_null_or_false");

function check_if_value_is_null_or_false($val) {
    return !is_null($val);       
};
Run Code Online (Sandbox Code Playgroud)

我知道我可以is_null用来过滤掉任何null有价值的东西.

我还想为string添加一个条件"False"作为值.

我该如何修改上述内容?

php arrays

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

Firebase云计算儿童大小的功能

firebase云功能API参考之后,我试图实现计数增加/减少:

Uploads/
     - Posts/
          - post_1
          - post_2
          ...

     - Likes/
          - post_1/
               - Number: 4
          - post_2/
               - Number: 2
          ...
Run Code Online (Sandbox Code Playgroud)

和,

 exports.LikeCount= functions.database.ref('/Posts/{postID}').onWrite(event => {
    const Ref     = event.data.ref;
    const postID  = event.params.postID; 
    const likeCount= Ref.parent.parent.child('/Likes/' + postID  + '/Number');           

    return likeCount.transaction(current => {         
        if (event.data.exists() && !event.data.previous.exists()) {
            return (current || 0) + 1;

        }else if (!event.data.exists() && event.data.previous.exists()) {
            return (current || 0) - 1;

        }

    }).then(() => {
        console.log("Done");         
    });
}); …
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-realtime-database google-cloud-functions

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