Skip to content

Instantly share code, notes, and snippets.

@millken
Created July 19, 2010 09:52
Show Gist options
  • Save millken/481219 to your computer and use it in GitHub Desktop.
Save millken/481219 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$('img[data^=maxsize_]').each(function(){
var size = $(this).attr('data').substring(8);
max = Math.min(this.width, this.height);
$(this).css({'width':this.width/max*size,'height':this.height/max*size});
});
});
jQuery(document).ready(function ($) {
$('.goods-detail-pic-thumbnail a').click(function(){
$('#showimage').attr('src', $(this).children('img').attr('c_src'));
$('.current').removeClass('current');
$(this).parent().addClass('current');
var size = $('#showimage').attr('data').substring(8);
var pw = parseInt($('#showimage').css('width'));
var ph = parseInt($('#showimage').css('height'))
var max = Math.max(pw, ph);
$('#showimage').css({'width':pw/max*size,'height':ph/max*size});
return false;
});
$('.scrollarrow').click(function(){
if($(this).hasClass('toleft'))
$(".goods-detail-pic-thumbnail").scrollLeft(-50);
if($(this).hasClass('toright'))
$(".goods-detail-pic-thumbnail").scrollLeft(50);
});
$('.goods-detail-pic-thumbnail a').eq(0).trigger('click');
$.tabs('.tabs div');
$('.numadjust').click(function(){
if($(this).hasClass('increase'))$('input[name=quantity]').val(parseInt($('input[name=quantity]').val()) + 1);
if($(this).hasClass('decrease') && parseInt($('input[name=quantity]').val())>1)$('input[name=quantity]').val(parseInt($('input[name=quantity]').val()) - 1);
});
});
@millken
Copy link
Author

millken commented Sep 25, 2010

        complete: function () {
            var image = $('#image').offset();
            var cart  = $('#module_cart').offset();

            $('#image').before('<img src="' + $('#image').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

            params = {
                top : cart.top + 'px',
                left : cart.left + 'px',
                opacity : 0.0,
                width : $('#module_cart').width(),  
                heigth : $('#module_cart').height()
            };      

            $('#temp').animate(params, 'slow', false, function () {
                $('#temp').remove();
            });     
        }

@millken
Copy link
Author

millken commented Sep 25, 2010

DOM方法:

父窗口操作IFRAME:window.frames["iframeSon"].document

IFRAME操作父窗口: window.parent.document

jquery方法:

在父窗口中操作 选中IFRAME中的所有输入框: $(window.frames["iframeSon"].document).find(”:text”);

在IFRAME中操作 选中父窗口中的所有输入框:$(window.parent.document).find(”:text”);

iframe框架的HTML:<iframe src=”test.html” id=”iframeSon” width=”700″ height=”300″ frameborder=”0″ scrolling=”auto”></iframe>

细心的朋友一下就能理解,原理其实很简单,就是用到了$(DOM对象)转换成jquery对象。

例子:

主页面

<title>主页面</title> <script type="text/javascript" src="css_js/jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript"> function showSubValue(){ //var v = window.frames[0].document.getElementById("subdiv1").innerHTML; //alert(v); var o = $(window.frames[0].document).find(":div#subdiv1"); alert(o.html()); } </script>
主页面测试数据
<iframe src="sub.html" width="300" height="300"></iframe>

子页面:

<script type="text/javascript" src="css_js/jquery/jquery-1.3.2.min.js"></script> <title>子页面</title> <script type="text/javascript"> function showMainValue(){ //dom方式 //var v = window.parent.document.getElementById("mainDiv").innerHTML; //alert(v); //window.parent.document.getElementById("mainDiv").innerHTML = "修改后的主页面数据"; //jquery方式 var o = $(window.parent.document).find(":div#mainDiv"); alert(o.html()); } </script>
子页面测试数据

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment