簡體   English   中英

選擇以WordPress小部件形式隱藏/顯示

[英]Select Hide/Show in WordPress Widget Form

所以這就是問題所在,我一直在嘗試使用jQuery將選擇的隱藏/顯示字段放入我的wordpress小部件表單中。 我已經准備好所有字段,只是腳本無法正常工作。 也許我做錯了事,但是我搜索了一下卻找不到答案,也許有人可以提供幫助。

<p class="dot-input-title">
        <label for="widget-bw_adspace-__i__-title">Title</label>
        <input class="widefat" id="widget-bw_adspace-__i__-title" name="widget-bw_adspace[__i__][title]" type="text" value="" />
    </p>

    <div class="dot-select-type">
        <select id="widget-bw_adspace-__i__-type" class="bw-select widefat" name="widget-bw_adspace[__i__][type]" >
                            <option value="upload" id="upload" >Upload Ad Image</option><option value="custom" id="custom" >Custom Script</option>          </select>

    </div>

    <div id="dot-input-upload">
        <label for="widget-bw_adspace-__i__-src">Upload Ad Image</label>
        <img style="width:100%" src="" />
        <input type="text" id="widget-bw_adspace-__i__-src" class="widefat bw_src" name="widget-bw_adspace[__i__][src]" value="" />
        <input type="button" class="bw_button button" name="widget-bw_adspace[__i__][src]_button" id="widget-bw_adspace-__i__-src_button" value="Upload" />
        <p>Use this field to upload or select and image from the media library.</p>

        <label for="widget-bw_adspace-__i__-url">Add URL</label>
        <input class="widefat" id="widget-bw_adspace-__i__-url" name="widget-bw_adspace[__i__][url]" type="text" value="" />
        <p>Add a URL to the selected ad.</p>
    </div>

    <div id="dot-textarea-custom-script">
        <label for="widget-bw_adspace-__i__-custom">Custom Script</label>
        <textarea class="widefat" id="widget-bw_adspace-__i__-custom" name="widget-bw_adspace[__i__][custom]" value="" col="20" rows="16"></textarea>
    </div>



jQuery(document).ready(function(){

    $('#dot-input-upload').hide();
    $('#dot-textarea-custom-script').hide();

    $('.bw-select').change(function() { 

        if ($(".bw-select").val() == "upload") {

                $("#dot-input-upload").show();
                $("#dot-textarea-custom-script").hide();

        } else {

                $("#dot-input-upload").hide();
        };

        if ($(".bw-select").val() == "custom") {

                $("#dot-input-upload").hide();
                $("#dot-textarea-custom-script").show();

        } else {

                $("#dot-textarea-custom-script").hide();
        };
    });

}); 

好吧,在這里。

<select id="widget-bw_adspace-__i__-type bw-select" class="bw-type widefat" name="widget-bw_adspace[__i__][type]" >

您使用$('.bw-select')但已將bw-select附加到ID而不是類上。

注意$('#bw-select')不會選擇該元素,因為ID無效,它具有空格。

jQuery(document).ready(function(){

改成

$(document).ready(function(){

或將所有$更改為jQuery;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM