繁体   English   中英

父 HTML 中子元素的通缉脚本标签元素

[英]Wanted script tag elements of child in parent HTML

有 2 个 html 文件: abcd.htmlxyz.html

abcd.html:

<html>
    <body>
        <div> <!-- src= xyz.html only body of it is taken--> 
    </body>
</html>

xyz.html:

<html>
    <body>
        <input type="radio" id="radio">
    </body>
</html>

文件: xyz.html ,包含一个单选按钮,我需要使用 jQuery 对其进行样式设置; 但是, xyz.htmlabcd.html的以下 jQuery 代码不起作用:

<script>
    $(document).ready(function(){
        styleRadio("radio");
    });
</script>
/* for this function styleRadio, the paramater passed is name parameter of the Radio button
function styleRadio(radioName){
        var radioButton = $('input[name="'+ radioName +'"]');
        $(radioButton).each(function(){
            $(this).wrap( "<span class='custom-radio'></span>" );
            if($(this).is(':checked')){
                $(this).parent().addClass("selected");
            }
        });
        $(radioButton).click(function(){
            if($(this).is(':checked')){
                $(this).parent().addClass("selected");
            }
            $(radioButton).not(this).each(function(){
                $(this).parent().removeClass("selected");
            });
        });
    }

css:

 .custom-radio{ width: 16px; height: 16px; display: inline-block; position: relative; z-index: 1; top: 3px; background: url("../images/radio.png") no-repeat; } .custom-radio:hover{ background: url("../images/radio-hover.png") no-repeat; } .custom-radio.selected{ background: url("../images/radio-selected.png") no-repeat; } .custom-radio input[type="radio"]{ margin: 1px; position: absolute; z-index: 2; cursor: pointer; outline: none; opacity: 0; /* CSS hacks for older browsers */ _noFocusLine: expression(this.hideFocus=true); -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: alpha(opacity=0); -khtml-opacity: 0; -moz-opacity: 0; }

在股利abcd.html加载的身体xyz.html ,在该链接的点击abcd.html

假设

function styleRadio(id) {
   $(id).css('opacity','0.5');
}

你需要使用:

<script>
    $(document).ready(function(){
        styleRadio("#radio");
    });
</script>

两个块都在abcd.html ,因为您的xyz.html从未用作 html,因此从未被解释过。

暂无
暂无

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

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