Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery mouseover附加的iframe(同一域)元素_Jquery_Html_Iframe_Javascript Events - Fatal编程技术网

Jquery mouseover附加的iframe(同一域)元素

Jquery mouseover附加的iframe(同一域)元素,jquery,html,iframe,javascript-events,Jquery,Html,Iframe,Javascript Events,以下是我喜欢做的一些事情。我想将鼠标移到iframe(同一个域)中的元素上,然后更改字体的颜色。例如 但在我的第一个版本中,iframe是在我按下按钮-。在我的例子中,鼠标盖不起作用,我不知道为什么。我对javascript没有那么丰富的经验,自己也无法理解。也许我想做的事情做不到,也许我只是错过了一些东西 function load_iframe(callback) { $('#iframe').append('<iframe class="ajax" scrolling="no

以下是我喜欢做的一些事情。我想将鼠标移到iframe(同一个域)中的元素上,然后更改字体的颜色。例如

但在我的第一个版本中,iframe是在我按下按钮-。在我的例子中,鼠标盖不起作用,我不知道为什么。我对javascript没有那么丰富的经验,自己也无法理解。也许我想做的事情做不到,也许我只是错过了一些东西

function load_iframe(callback) {
    $('#iframe').append('<iframe class="ajax" scrolling="no" style="height:190px" src="http://fiddle.jshell.net/38g2pyxh/"></iframe>')
    $('.ajax').load(function() {
        callback(this);
    });
}

$(document).on('click','#create',function(callback){
    load_iframe(function(){
    iframe = $('iframe.ajax').contents()
    iframe.find('body').prepend('<b>This is a test</b><br><b>Click here</b>');
    })
    return iframe
})

iframe.on('mouseover', 'b', function() {
    $(this).css('color','red');
});
函数加载iframe(回调){
$('#iframe')。附加('')
$('.ajax').load(函数(){
回调(这个);
});
}
$(文档).on('click','#create',函数(回调){
加载iframe(函数(){
iframe=$('iframe.ajax').contents()
iframe.find('body').prepend('This is a test
Click here'); }) 返回iframe }) on('mouseover','b',function(){ $(this.css('color','red'); });

我到目前为止所做的

这是简单的代码,我希望能帮助您。。。。我正在编辑您的代码

var iframe
var a
function load_iframe(callback) {

        $('#iframe').append('<iframe id="1a" class="ajax" scrolling="no" style="height:190px" src="http://fiddle.jshell.net/38g2pyxh/"></iframe>')
        $('.ajax').load(function() {
            callback(this);
        });
    }

    $(document).on('click','#create',function(callback){

                load_iframe(function(){
                    iframe = $('iframe.ajax').contents()
                    iframe.find('body').prepend('<b id="bb">This is a test</b><br><b>Click here</b>');
                      a=document.getElementById('1a').contentWindow.document.getElementById('bb')
    alert('pass')
     a.onmouseover=function(){
     a.style.color="red"
    }
       a.onmouseleave=function(){
     a.style.color="black"
    }
                })

            return iframe
    })
var-iframe
变量a
函数加载iframe(回调){
$('#iframe')。附加('')
$('.ajax').load(函数(){
回调(这个);
});
}
$(文档).on('click','#create',函数(回调){
加载iframe(函数(){
iframe=$('iframe.ajax').contents()
iframe.find('body').prepend('This is a test
Click here'); a=document.getElementById('1a').contentWindow.document.getElementById('bb')) 警报(‘通过’) a、 onmouseover=函数(){ a、 style.color=“红色” } a、 onmouseleave=函数(){ a、 style.color=“黑色” } }) 返回iframe })