$("iframe").each(function() {
var src= $(this).attr('src');
$(this).attr('src',src);
});
stockwfj3 發表在 痞客邦 留言(0) 人氣(113)
<div id="top"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$("#top").load( "top.html");
</script>
stockwfj3 發表在 痞客邦 留言(0) 人氣(3,937)
<script>
// Find all iframes
var $iframes = $("iframe" );
// Find & save the aspect ratio for all iframes
$iframes.each(function () {
$( this ).data( "ratio", this.height / this.width )
// Remove the hardcoded width & height attributes
.removeAttr( "width" )
.removeAttr( "height" );
});
// Resize the iframes when the window is resized
$( window ).resize( function () {
$iframes.each( function() {
// Get the parent container's width
var width = $( this ).parent().width();
$( this ).width( width )
.height( width * $( this ).data( "ratio" ) );
});
// Resize to fix all iframes on page load.
}).resize();
</script>
stockwfj3 發表在 痞客邦 留言(0) 人氣(454)
用法
$("#元素").removeAttr('屬性值');
例:
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").removeAttr("style");
});
});
</script>
stockwfj3 發表在 痞客邦 留言(0) 人氣(124)
例:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>prop demo</title>
<style>
p {
margin: 20px 0 0;
}
b {
color: blue;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<input id="check1" type="checkbox" checked="checked">
<label for="check1">Check me</label>
<p></p>
<script>
$( "input" ).change(function() {
var $input = $( this );
$( "p" ).html(
".attr( \"checked\" ): <b>" + $input.attr( "checked" ) + "</b><br>" +
".prop( \"checked\" ): <b>" + $input.prop( "checked" ) + "</b><br>" +
".is( \":checked\" ): <b>" + $input.is( ":checked" ) + "</b>" );
}).change();
</script>
</body>
</html>
stockwfj3 發表在 痞客邦 留言(0) 人氣(275)
例:返回被選中元素的內容
$("元素").html()
例:設定一個值,並覆蓋被選中元素的所有內容
$(元素).html(內容)
stockwfj3 發表在 痞客邦 留言(0) 人氣(31)
檢查第一個段落是否擁class等於"intro"
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
alert($("p:first").hasClass("intro")); //顯示true
});
});
</script>
stockwfj3 發表在 痞客邦 留言(0) 人氣(40)
1.變更屬性值
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("img").attr("width","180"); //變更屬性值
});
});
</script>
stockwfj3 發表在 痞客邦 留言(0) 人氣(205)
一次可以添加一個以上的css class,由一個空格分隔,以匹配元素的集合,如下所示:
$("p").addClass( "myClass yourClass" );
這種方法通常用於.removeClass()將元素的類從一個切換到另一個,如下所示:
stockwfj3 發表在 痞客邦 留言(0) 人氣(459)
jQuery('#id').on('click', function(){
window.location='網址';
});
stockwfj3 發表在 痞客邦 留言(0) 人氣(295)