[英]Wanted script tag elements of child in parent HTML
有 2 个 html 文件: abcd.html
和xyz.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.html
和abcd.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.